image upload and keep if not changed
This commit is contained in:
parent
be52a51055
commit
5b3a72820a
3 changed files with 17 additions and 9 deletions
|
@ -70,13 +70,13 @@ export async function setSettings<K extends SettingString>(req: Request, res: Re
|
|||
export async function setImages(req: Request, res: Response): Promise<any> {
|
||||
if (req.files && !Array.isArray(req.files) && req.files.icon) {
|
||||
await SettingHelper.setSetting("club.icon", "configured");
|
||||
} else {
|
||||
} else if (req.body["club.icon"] != "keep") {
|
||||
await SettingHelper.resetSetting("club.icon");
|
||||
}
|
||||
|
||||
if (req.files && !Array.isArray(req.files) && req.files.logo) {
|
||||
await SettingHelper.setSetting("club.logo", "configured");
|
||||
} else {
|
||||
} else if (req.body["club.logo"] != "keep") {
|
||||
await SettingHelper.resetSetting("club.logo");
|
||||
}
|
||||
|
||||
|
|
|
@ -130,10 +130,10 @@ export async function getApplicationLogo(req: Request, res: Response): Promise<a
|
|||
"Timing-Allow-Origin": "*",
|
||||
});
|
||||
|
||||
if (setLogo == "") {
|
||||
res.sendFile(FileSystemHelper.readAssetFile("admin-logo.png", true));
|
||||
} else {
|
||||
if (setLogo != "" && FileSystemHelper.getFilesInDirectory("/app", ".png").includes("admin-icon.png")) {
|
||||
res.sendFile(FileSystemHelper.formatPath("/app/admin-logo.png"));
|
||||
} else {
|
||||
res.sendFile(FileSystemHelper.readAssetFile("admin-logo.png", true));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,8 +147,8 @@ export async function getApplicationFavicon(req: Request, res: Response): Promis
|
|||
let icon = FileSystemHelper.readAssetFile("icon.png", true);
|
||||
let setLogo = SettingHelper.getSetting("club.icon");
|
||||
|
||||
if (setLogo != "") {
|
||||
icon = FileSystemHelper.formatPath("/app/icon.png");
|
||||
if (setLogo != "" && FileSystemHelper.getFilesInDirectory("/app", ".png").includes("admin-icon.png")) {
|
||||
icon = FileSystemHelper.formatPath("/app/admin-icon.png");
|
||||
}
|
||||
|
||||
let image = await sharp(icon)
|
||||
|
@ -184,8 +184,8 @@ export async function getApplicationIcon(req: Request, res: Response): Promise<a
|
|||
let icon = FileSystemHelper.readAssetFile("icon.png", true);
|
||||
let setLogo = SettingHelper.getSetting("club.icon");
|
||||
|
||||
if (setLogo != "") {
|
||||
icon = FileSystemHelper.formatPath("/app/icon.png");
|
||||
if (setLogo != "" && FileSystemHelper.getFilesInDirectory("/app", ".png").includes("admin-icon.png")) {
|
||||
icon = FileSystemHelper.formatPath("/app/admin-icon.png");
|
||||
}
|
||||
|
||||
let image = await sharp(icon)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import multer from "multer";
|
||||
import { FileSystemHelper } from "../helpers/fileSystemHelper";
|
||||
import path from "path";
|
||||
import BadRequestException from "../exceptions/badRequestException";
|
||||
|
||||
export const clubImageStorage = multer.diskStorage({
|
||||
destination: FileSystemHelper.formatPath("/app"),
|
||||
|
@ -19,6 +20,13 @@ export const clubImageStorage = multer.diskStorage({
|
|||
|
||||
export const clubImageMulter = multer({
|
||||
storage: clubImageStorage,
|
||||
fileFilter(req, file, cb) {
|
||||
if (file.mimetype.startsWith("image/png")) {
|
||||
cb(null, true);
|
||||
} else {
|
||||
cb(new BadRequestException("Wrong file format"));
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const clubImageUpload = clubImageMulter.fields([
|
||||
|
|
Loading…
Add table
Reference in a new issue