fix: maintenance service preview files bug
This commit is contained in:
1 parent
7a21c6ebd8
commit
f50cf0ae31
1 file changed
+4
-4
@@ -2,15 +2,15 @@ const path = require('path');
|
|||||||
const fsPromises = require('fs').promises;
|
const fsPromises = require('fs').promises;
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const Media = require("../models/Media");
|
const Media = require("../models/Media");
|
||||||
const { getSettings } = require("./settingsService");
|
|
||||||
const { logToFile } = require('./logService');
|
const { logToFile } = require('./logService');
|
||||||
|
const { getMediaFolder } = require('./mediaService');
|
||||||
|
|
||||||
|
|
||||||
async function deleteMissingFilesEntries(dry = false) {
|
async function deleteMissingFilesEntries(dry = false) {
|
||||||
const allMedia = await Media.findAll();
|
const allMedia = await Media.findAll();
|
||||||
|
|
||||||
// Getting the userDataPath to store the images
|
// Getting the userDataPath to store the images
|
||||||
const dataPath = getSettings().userDataPath;
|
const dataPath = await getMediaFolder();
|
||||||
|
|
||||||
// Handling different media types
|
// Handling different media types
|
||||||
const mediaTypes = {
|
const mediaTypes = {
|
||||||
@@ -20,7 +20,7 @@ async function deleteMissingFilesEntries(dry = false) {
|
|||||||
};
|
};
|
||||||
let missingFiles = [];
|
let missingFiles = [];
|
||||||
for (let i = 0; i < allMedia.length; i++) {
|
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)
|
const filePath = path.join(mediaTypes[type], allMedia[i].path)
|
||||||
if (!fs.existsSync(filePath)) {
|
if (!fs.existsSync(filePath)) {
|
||||||
missingFiles.push(allMedia[i]);
|
missingFiles.push(allMedia[i]);
|
||||||
@@ -50,7 +50,7 @@ async function deleteMissingFilesEntries(dry = false) {
|
|||||||
|
|
||||||
async function deleteOrphanFiles(dry = false) {
|
async function deleteOrphanFiles(dry = false) {
|
||||||
// Getting the userDataPath to store the images
|
// 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
|
// ? Getting the path of all media files and putting them in an array
|
||||||
const allMedia = (await Media.findAll()).map(m =>
|
const allMedia = (await Media.findAll()).map(m =>
|
||||||
|
|||||||
Reference in new issue
Block a user