aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-10 15:26:33 +0200
committerChocobozzz <me@florianbigard.com>2019-04-10 16:38:32 +0200
commitfd8710b897a67518d3a61c319e54b6a65ba443ef (patch)
treed9953b7e0bb4e5a119c872ab21021f4c1ab33bea /shared
parent31b6ddf86652502e0c96d77fa10861ce4af11aa4 (diff)
downloadPeerTube-fd8710b897a67518d3a61c319e54b6a65ba443ef.tar.gz
PeerTube-fd8710b897a67518d3a61c319e54b6a65ba443ef.tar.zst
PeerTube-fd8710b897a67518d3a61c319e54b6a65ba443ef.zip
Add logs endpoint
Diffstat (limited to 'shared')
-rw-r--r--shared/models/server/log-level.type.ts1
-rw-r--r--shared/models/users/user-right.enum.ts2
-rw-r--r--shared/utils/logs/logs.ts41
3 files changed, 44 insertions, 0 deletions
diff --git a/shared/models/server/log-level.type.ts b/shared/models/server/log-level.type.ts
new file mode 100644
index 000000000..ce91559e3
--- /dev/null
+++ b/shared/models/server/log-level.type.ts
@@ -0,0 +1 @@
export type LogLevel = 'debug' | 'info' | 'warn' | 'error'
diff --git a/shared/models/users/user-right.enum.ts b/shared/models/users/user-right.enum.ts
index eaa064bd9..5ec255ea5 100644
--- a/shared/models/users/user-right.enum.ts
+++ b/shared/models/users/user-right.enum.ts
@@ -5,6 +5,8 @@ export enum UserRight {
5 5
6 MANAGE_SERVER_FOLLOW, 6 MANAGE_SERVER_FOLLOW,
7 7
8 MANAGE_LOGS,
9
8 MANAGE_SERVER_REDUNDANCY, 10 MANAGE_SERVER_REDUNDANCY,
9 11
10 MANAGE_VIDEO_ABUSES, 12 MANAGE_VIDEO_ABUSES,
diff --git a/shared/utils/logs/logs.ts b/shared/utils/logs/logs.ts
new file mode 100644
index 000000000..21adace82
--- /dev/null
+++ b/shared/utils/logs/logs.ts
@@ -0,0 +1,41 @@
1// Thanks: https://stackoverflow.com/a/37014317
2import { stat } from 'fs-extra'
3import { makeGetRequest } from '../requests/requests'
4import { LogLevel } from '../../models/server/log-level.type'
5
6async function mtimeSortFilesDesc (files: string[], basePath: string) {
7 const promises = []
8 const out: { file: string, mtime: number }[] = []
9
10 for (const file of files) {
11 const p = stat(basePath + '/' + file)
12 .then(stats => {
13 if (stats.isFile()) out.push({ file, mtime: stats.mtime.getTime() })
14 })
15
16 promises.push(p)
17 }
18
19 await Promise.all(promises)
20
21 out.sort((a, b) => b.mtime - a.mtime)
22
23 return out
24}
25
26function getLogs (url: string, accessToken: string, startDate: Date, endDate?: Date, level?: LogLevel) {
27 const path = '/api/v1/server/logs'
28
29 return makeGetRequest({
30 url,
31 path,
32 token: accessToken,
33 query: { startDate, endDate, level },
34 statusCodeExpected: 200
35 })
36}
37
38export {
39 mtimeSortFilesDesc,
40 getLogs
41}