mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 19:14:16 +00:00
implement default posting_policy
This commit is contained in:
parent
acd0dae11c
commit
8d25e7c151
@ -87,6 +87,29 @@ export default class Server {
|
|||||||
|
|
||||||
global.jwtStrategy = this.options.jwtStrategy
|
global.jwtStrategy = this.options.jwtStrategy
|
||||||
global.signLocation = this.env.signLocation
|
global.signLocation = this.env.signLocation
|
||||||
|
|
||||||
|
global.DEFAULT_POSTING_POLICY = {
|
||||||
|
maxMessageLength: 512,
|
||||||
|
acceptedMimeTypes: [
|
||||||
|
"image/jpg",
|
||||||
|
"image/jpeg",
|
||||||
|
"image/png",
|
||||||
|
"image/gif",
|
||||||
|
"audio/mp3",
|
||||||
|
"audio/mpeg",
|
||||||
|
"audio/ogg",
|
||||||
|
"audio/wav",
|
||||||
|
"audio/flac",
|
||||||
|
"video/mp4",
|
||||||
|
"video/mkv",
|
||||||
|
"video/webm",
|
||||||
|
"video/quicktime",
|
||||||
|
"video/x-msvideo",
|
||||||
|
"video/x-ms-wmv",
|
||||||
|
],
|
||||||
|
maximumFileSize: 80 * 1024 * 1024,
|
||||||
|
maximunFilesPerRequest: 20,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async initialize() {
|
async initialize() {
|
||||||
|
@ -7,38 +7,7 @@ import { videoTranscode } from "../../lib/videoTranscode"
|
|||||||
|
|
||||||
const formidable = require("formidable")
|
const formidable = require("formidable")
|
||||||
|
|
||||||
// TODO: Get maximunFileSize by type of user subscription (free, premium, etc) when `PermissionsAPI` is ready
|
|
||||||
const maximumFileSize = 80 * 1024 * 1024 // max file size in bytes (80MB) By default, the maximum file size is 80MB.
|
|
||||||
const maximunFilesPerRequest = 20
|
|
||||||
const acceptedMimeTypes = [
|
|
||||||
"image/jpg",
|
|
||||||
"image/jpeg",
|
|
||||||
"image/png",
|
|
||||||
"image/gif",
|
|
||||||
"audio/mp3",
|
|
||||||
"audio/mpeg",
|
|
||||||
"audio/ogg",
|
|
||||||
"audio/wav",
|
|
||||||
"audio/flac",
|
|
||||||
"video/mp4",
|
|
||||||
"video/mkv",
|
|
||||||
"video/webm",
|
|
||||||
"video/quicktime",
|
|
||||||
"video/x-msvideo",
|
|
||||||
"video/x-ms-wmv",
|
|
||||||
]
|
|
||||||
|
|
||||||
export default class FilesController extends Controller {
|
export default class FilesController extends Controller {
|
||||||
get = {
|
|
||||||
"/upload/policy": (req, res) => {
|
|
||||||
return res.json({
|
|
||||||
acceptedMimeTypes,
|
|
||||||
maximumFileSize,
|
|
||||||
maximunFilesPerRequest,
|
|
||||||
})
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
post = {
|
post = {
|
||||||
"/upload": {
|
"/upload": {
|
||||||
middlewares: ["withAuthentication"],
|
middlewares: ["withAuthentication"],
|
||||||
@ -55,8 +24,8 @@ export default class FilesController extends Controller {
|
|||||||
multiples: true,
|
multiples: true,
|
||||||
keepExtensions: true,
|
keepExtensions: true,
|
||||||
uploadDir: global.uploadCachePath,
|
uploadDir: global.uploadCachePath,
|
||||||
maxFileSize: maximumFileSize,
|
maxFileSize: global.DEFAULT_POSTING_POLICY.maximumFileSize,
|
||||||
maxFields: maximunFilesPerRequest,
|
maxFields: global.DEFAULT_POSTING_POLICY.maximunFilesPerRequest,
|
||||||
filename: (name, ext) => {
|
filename: (name, ext) => {
|
||||||
name = name.trim()
|
name = name.trim()
|
||||||
name = name.replace(/ /g, "_")
|
name = name.replace(/ /g, "_")
|
||||||
@ -66,7 +35,7 @@ export default class FilesController extends Controller {
|
|||||||
},
|
},
|
||||||
filter: (stream) => {
|
filter: (stream) => {
|
||||||
// check if is allowed mime type
|
// check if is allowed mime type
|
||||||
if (!acceptedMimeTypes.includes(stream.mimetype)) {
|
if (!global.DEFAULT_POSTING_POLICY.acceptedMimeTypes.includes(stream.mimetype)) {
|
||||||
failed.push({
|
failed.push({
|
||||||
fileName: file.originalFilename,
|
fileName: file.originalFilename,
|
||||||
mimetype: file.mimetype,
|
mimetype: file.mimetype,
|
||||||
|
@ -7,6 +7,13 @@ export default class PublicController extends Controller {
|
|||||||
static refName = "PublicController"
|
static refName = "PublicController"
|
||||||
|
|
||||||
get = {
|
get = {
|
||||||
|
"/posting_policy": {
|
||||||
|
middlewares: ["withOptionalAuthentication"],
|
||||||
|
fn: async (req, res) => {
|
||||||
|
// TODO: Use `PermissionsAPI` to get the user's permissions and return the correct policy, by now it will return the default policy
|
||||||
|
return res.json(global.DEFAULT_POSTING_POLICY)
|
||||||
|
}
|
||||||
|
},
|
||||||
"/featured_wallpapers": {
|
"/featured_wallpapers": {
|
||||||
fn: async (req, res) => {
|
fn: async (req, res) => {
|
||||||
const featuredWallpapers = await FeaturedWallpaper.find({})
|
const featuredWallpapers = await FeaturedWallpaper.find({})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user