mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
added PlaylistController
This commit is contained in:
parent
25660c4370
commit
502585cd65
@ -1,6 +1,8 @@
|
|||||||
import { Controller } from "linebridge/dist/server"
|
import { Controller } from "linebridge/dist/server"
|
||||||
import { Schematized } from "../../lib"
|
import { Schematized } from "../../lib"
|
||||||
|
|
||||||
|
import publishPlaylist from "./methods/publishPlaylist"
|
||||||
|
|
||||||
export default class PlaylistsController extends Controller {
|
export default class PlaylistsController extends Controller {
|
||||||
//static useMiddlewares = ["withAuthentication"]
|
//static useMiddlewares = ["withAuthentication"]
|
||||||
|
|
||||||
@ -13,9 +15,35 @@ export default class PlaylistsController extends Controller {
|
|||||||
post = {
|
post = {
|
||||||
"/playlist/publish": {
|
"/playlist/publish": {
|
||||||
middlewares: ["withAuthentication"],
|
middlewares: ["withAuthentication"],
|
||||||
fn: async (req, res) => {
|
fn: Schematized({
|
||||||
|
required: ["title", "list"],
|
||||||
}
|
select: ["title", "description", "thumbnail", "list"],
|
||||||
|
},async (req, res) => {
|
||||||
|
if (typeof req.body.list === "undefined") {
|
||||||
|
return res.status(400).json({
|
||||||
|
error: "list is required"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse
|
||||||
|
req.selection.list = JSON.parse(req.selection.list)
|
||||||
|
|
||||||
|
const result = await publishPlaylist({
|
||||||
|
user_id: req.user._id.toString(),
|
||||||
|
...req.selection
|
||||||
|
}).catch((err) => {
|
||||||
|
res.status(500).json({
|
||||||
|
error: err.message
|
||||||
|
})
|
||||||
|
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
return res.json(result)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
import { Playlist } from "../../../models"
|
||||||
|
|
||||||
|
export default async (payload) => {
|
||||||
|
const { user_id, title, description, thumbnail, list } = payload
|
||||||
|
|
||||||
|
const playlist = new Playlist({
|
||||||
|
user_id,
|
||||||
|
created_at: Date.now(),
|
||||||
|
title: title ?? "Untitled",
|
||||||
|
description,
|
||||||
|
thumbnail,
|
||||||
|
list,
|
||||||
|
})
|
||||||
|
|
||||||
|
await playlist.save()
|
||||||
|
|
||||||
|
global.eventBus.emit("playlist.created", playlist)
|
||||||
|
|
||||||
|
return playlist
|
||||||
|
}
|
@ -10,4 +10,5 @@ export { default as StreamingController } from "./StreamingController"
|
|||||||
export { default as BadgesController } from "./BadgesController"
|
export { default as BadgesController } from "./BadgesController"
|
||||||
export { default as CommentsController } from "./CommentsController"
|
export { default as CommentsController } from "./CommentsController"
|
||||||
export { default as SearchController } from "./SearchController"
|
export { default as SearchController } from "./SearchController"
|
||||||
export { default as FeaturedEventsController } from "./FeaturedEventsController"
|
export { default as FeaturedEventsController } from "./FeaturedEventsController"
|
||||||
|
export { default as PlaylistsController } from "./PlaylistsController"
|
Loading…
x
Reference in New Issue
Block a user