fix: maintenance service preview files bug

This commit is contained in:
X4Lo committed 2024-06-20 23:17:40 +01:00
1 parent 7a21c6ebd8
commit f50cf0ae31
1 file changed
+4 -4
+4 -4
View File
@@ -2,15 +2,15 @@ const path = require('path');
const fsPromises = require('fs').promises;
const fs = require('fs');
const Media = require("../models/Media");
const { getSettings } = require("./settingsService");
const { logToFile } = require('./logService');
const { getMediaFolder } = require('./mediaService');
async function deleteMissingFilesEntries(dry = false) {
const allMedia = await Media.findAll();
// Getting the userDataPath to store the images
const dataPath = getSettings().userDataPath;
const dataPath = await getMediaFolder();
// Handling different media types
const mediaTypes = {
@@ -20,7 +20,7 @@ async function deleteMissingFilesEntries(dry = false) {
};
let missingFiles = [];
for (let i = 0; i < allMedia.length; i++) {
let type = `${allMedia[i].type}`;
let type = `${allMedia[i].type}`.replace("_preview", "");
const filePath = path.join(mediaTypes[type], allMedia[i].path)
if (!fs.existsSync(filePath)) {
missingFiles.push(allMedia[i]);
@@ -50,7 +50,7 @@ async function deleteMissingFilesEntries(dry = false) {
async function deleteOrphanFiles(dry = false) {
// Getting the userDataPath to store the images
const dataPath = getSettings().userDataPath;
const dataPath = getMediaFolder();
// ? Getting the path of all media files and putting them in an array
const allMedia = (await Media.findAll()).map(m =>