nfp_sites/filadelfia_archive/api/article/routes.mjs

53 lines
1.8 KiB
JavaScript
Raw Normal View History

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'
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) {
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))
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) {
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'),
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
}
}