2023-11-20 07:12:08 +00:00
|
|
|
import config from '../../base/config.mjs'
|
|
|
|
import Client from '../../base/media/client.mjs'
|
|
|
|
import OriginalArticleRoutes from '../../base/article/routes.mjs'
|
|
|
|
import { deleteFile, uploadFile } from '../../base/media/upload.mjs'
|
|
|
|
import { parseVideos, parseVideo } from './util.mjs'
|
2023-11-30 04:14:42 +00:00
|
|
|
import { RankLevels } from '../../base/authentication/security.mjs'
|
2023-11-20 07:12:08 +00:00
|
|
|
|
|
|
|
export default class ArticleRoutes extends OriginalArticleRoutes {
|
|
|
|
constructor(opts = {}) {
|
|
|
|
opts.requireAuth = true
|
|
|
|
super(opts)
|
|
|
|
|
|
|
|
Object.assign(this, {
|
|
|
|
uploadFile: uploadFile,
|
|
|
|
deleteFile: deleteFile,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
register(server) {
|
2023-11-30 04:14:42 +00:00
|
|
|
server.flaska.get('/api/articles', this.getVideos.bind(this))
|
|
|
|
server.flaska.get('/api/articles/:path', this.getArticle.bind(this))
|
2023-11-20 07:12:08 +00:00
|
|
|
server.flaska.put('/api/auth/articles/:id', [server.authenticate(), server.jsonHandler()], this.updateCreateArticle.bind(this))
|
2023-11-30 04:14:42 +00:00
|
|
|
server.flaska.get('/api/auth/uploadToken', server.authenticate(RankLevels.Admin), this.getUploadToken.bind(this))
|
|
|
|
server.flaska.delete('/api/auth/articles/:id', server.authenticate(RankLevels.Admin), this.auth_removeSingleArticle.bind(this))
|
2023-11-20 07:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** GET: /api/auth/articles */
|
|
|
|
async getVideos(ctx) {
|
2023-11-30 04:14:42 +00:00
|
|
|
let res = await ctx.db.safeCallProc('filadelfia_archive.article_get_all', [])
|
2023-11-20 07:12:08 +00:00
|
|
|
|
|
|
|
ctx.body = {
|
|
|
|
videos: parseVideos(res.results[0]),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** GET: /api/auth/uploadToken */
|
|
|
|
async getUploadToken(ctx) {
|
|
|
|
const media = config.get('media')
|
|
|
|
|
|
|
|
ctx.body = {
|
|
|
|
token: Client.createJwt({ iss: media.iss }, media.secret),
|
|
|
|
path: config.get('media:directFilePath'),
|
2023-11-29 19:19:41 +00:00
|
|
|
resize: config.get('media:path'),
|
2023-11-30 04:14:42 +00:00
|
|
|
delete: config.get('media:removePath'),
|
2023-11-20 07:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** PUT: /api/auth/articles/:id */
|
|
|
|
async updateCreateArticle(ctx) {
|
2023-11-29 19:19:41 +00:00
|
|
|
return this.private_getUpdateArticle(ctx, ctx.req.body, ctx.req.body.banner, ctx.req.body.media)
|
2023-11-20 07:12:08 +00:00
|
|
|
}
|
|
|
|
}
|