Skip to content

Commit 10d333f

Browse files
committed
feat: add log page
1 parent 5f9924e commit 10d333f

File tree

17 files changed

+1032
-5
lines changed

17 files changed

+1032
-5
lines changed

bun.lockb

351 Bytes
Binary file not shown.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@
3535
"typescript": "~5.7.3",
3636
"valid-url": "^1.0.9"
3737
},
38-
"type": "module"
38+
"type": "module",
39+
"dependencies": {
40+
"prismjs": "^1.29.0"
41+
}
3942
}

src/lib/api/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@ async function invoke (fn, args, fetch) {
4848
return body
4949
}
5050

51+
/**
52+
* @template T
53+
* @param {string} indexId
54+
* @param {string} fn
55+
* @param {Object} args
56+
* @param {fetch} fetch
57+
* @returns {Promise<Api.ResponseLog<T>>}
58+
*/
59+
async function invokeLog (indexId, fn, args, fetch) {
60+
const url = `${indexId}${fn ? ('/' + fn) : ''}${args ? ('?' + args) : ''}`
61+
const resp = await fetch(`${endpoint}/log/${encodeURIComponent(url)}`, {
62+
method: 'POST',
63+
headers: {
64+
'content-type': 'application/json'
65+
}
66+
})
67+
68+
const body = await resp.json()
69+
return body
70+
}
71+
5172
/**
5273
* @param {Function} callback
5374
*/
@@ -90,6 +111,7 @@ function intervalInvalidate (callback, interval) {
90111

91112
export default {
92113
invoke,
114+
invokeLog,
93115
setOnUnauth,
94116
invalidate: wrapInvalidate,
95117
intervalInvalidate

src/lib/format/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ export function datetime (v) {
5656
return dayjs(v).format('YYYY-MM-DD HH:mm:ss')
5757
}
5858

59+
/**
60+
* @param {string} v
61+
* @returns {number}
62+
*/
63+
export function unixDatetime (v) {
64+
if (!v) {
65+
return 0
66+
}
67+
return dayjs(v).unix()
68+
}
69+
5970
/**
6071
* @param {string} project
6172
* @param {string} name

src/lib/use-action/clickAway.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default function clickAway (node) {
2+
const handleClick = (event) => {
3+
if (node && !node.contains(event.target) && !event.defaultPrevented) {
4+
node.dispatchEvent(new CustomEvent('clickAway'))
5+
}
6+
}
7+
8+
document.addEventListener('click', handleClick, true)
9+
10+
return {
11+
destroy () {
12+
document.removeEventListener('click', handleClick, true)
13+
}
14+
}
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export async function load ({ url }) {
2+
const duration = url.searchParams.get('duration') || ''
3+
const startDate = url.searchParams.get('startDate') || ''
4+
const endDate = url.searchParams.get('endDate') || ''
5+
const query = url.searchParams.get('query') || ''
6+
const indexId = url.searchParams.get('indexId') || ''
7+
const endpoint = url.searchParams.get('endpoint') || ''
8+
9+
return {
10+
duration,
11+
startDate,
12+
endDate,
13+
query,
14+
indexId,
15+
endpoint
16+
}
17+
}

0 commit comments

Comments
 (0)