diff options
Diffstat (limited to 'server/controllers/api/video-channel-sync.ts')
-rw-r--r-- | server/controllers/api/video-channel-sync.ts | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/server/controllers/api/video-channel-sync.ts b/server/controllers/api/video-channel-sync.ts deleted file mode 100644 index 6b52ac7dd..000000000 --- a/server/controllers/api/video-channel-sync.ts +++ /dev/null | |||
@@ -1,79 +0,0 @@ | |||
1 | import express from 'express' | ||
2 | import { auditLoggerFactory, getAuditIdFromRes, VideoChannelSyncAuditView } from '@server/helpers/audit-logger' | ||
3 | import { logger } from '@server/helpers/logger' | ||
4 | import { | ||
5 | apiRateLimiter, | ||
6 | asyncMiddleware, | ||
7 | asyncRetryTransactionMiddleware, | ||
8 | authenticate, | ||
9 | ensureCanManageChannelOrAccount, | ||
10 | ensureSyncExists, | ||
11 | ensureSyncIsEnabled, | ||
12 | videoChannelSyncValidator | ||
13 | } from '@server/middlewares' | ||
14 | import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync' | ||
15 | import { MChannelSyncFormattable } from '@server/types/models' | ||
16 | import { HttpStatusCode, VideoChannelSyncState } from '@shared/models' | ||
17 | |||
18 | const videoChannelSyncRouter = express.Router() | ||
19 | const auditLogger = auditLoggerFactory('channel-syncs') | ||
20 | |||
21 | videoChannelSyncRouter.use(apiRateLimiter) | ||
22 | |||
23 | videoChannelSyncRouter.post('/', | ||
24 | authenticate, | ||
25 | ensureSyncIsEnabled, | ||
26 | asyncMiddleware(videoChannelSyncValidator), | ||
27 | ensureCanManageChannelOrAccount, | ||
28 | asyncRetryTransactionMiddleware(createVideoChannelSync) | ||
29 | ) | ||
30 | |||
31 | videoChannelSyncRouter.delete('/:id', | ||
32 | authenticate, | ||
33 | asyncMiddleware(ensureSyncExists), | ||
34 | ensureCanManageChannelOrAccount, | ||
35 | asyncRetryTransactionMiddleware(removeVideoChannelSync) | ||
36 | ) | ||
37 | |||
38 | export { videoChannelSyncRouter } | ||
39 | |||
40 | // --------------------------------------------------------------------------- | ||
41 | |||
42 | async function createVideoChannelSync (req: express.Request, res: express.Response) { | ||
43 | const syncCreated: MChannelSyncFormattable = new VideoChannelSyncModel({ | ||
44 | externalChannelUrl: req.body.externalChannelUrl, | ||
45 | videoChannelId: req.body.videoChannelId, | ||
46 | state: VideoChannelSyncState.WAITING_FIRST_RUN | ||
47 | }) | ||
48 | |||
49 | await syncCreated.save() | ||
50 | syncCreated.VideoChannel = res.locals.videoChannel | ||
51 | |||
52 | auditLogger.create(getAuditIdFromRes(res), new VideoChannelSyncAuditView(syncCreated.toFormattedJSON())) | ||
53 | |||
54 | logger.info( | ||
55 | 'Video synchronization for channel "%s" with external channel "%s" created.', | ||
56 | syncCreated.VideoChannel.name, | ||
57 | syncCreated.externalChannelUrl | ||
58 | ) | ||
59 | |||
60 | return res.json({ | ||
61 | videoChannelSync: syncCreated.toFormattedJSON() | ||
62 | }) | ||
63 | } | ||
64 | |||
65 | async function removeVideoChannelSync (req: express.Request, res: express.Response) { | ||
66 | const syncInstance = res.locals.videoChannelSync | ||
67 | |||
68 | await syncInstance.destroy() | ||
69 | |||
70 | auditLogger.delete(getAuditIdFromRes(res), new VideoChannelSyncAuditView(syncInstance.toFormattedJSON())) | ||
71 | |||
72 | logger.info( | ||
73 | 'Video synchronization for channel "%s" with external channel "%s" deleted.', | ||
74 | syncInstance.VideoChannel.name, | ||
75 | syncInstance.externalChannelUrl | ||
76 | ) | ||
77 | |||
78 | return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end() | ||
79 | } | ||