Backend: minor fixes + Added people media folder auto creating & mutler upload function
This commit is contained in:
1 parent
d3dbd7c3e3
commit
f1cd3f9167
4 files changed
+29
-14
No files matched your search
@@ -20,17 +20,15 @@ class MaintenanceService {
|
||||
|
||||
/**
|
||||
* Delete orphan media records from database,
|
||||
* orphan media records are media records that exist in the database
|
||||
* but do not have a file in the `folder data`
|
||||
* these are media records that exist in the database
|
||||
* but do not have a file in the `user data folder`.
|
||||
* @param {boolean} [dry=false] - if true only return the count of the files that are getting deleted, default=`false`
|
||||
*/
|
||||
async deleteOrphanMediaRecords(dry = false) {
|
||||
const allMedia = await Media.findAll();
|
||||
|
||||
// Getting the userDataPath to store the images
|
||||
const dataPath = await _configService.getMediaFolder();
|
||||
|
||||
// Handling different media types
|
||||
const mediaTypeFolder = {
|
||||
'entry;poster': path.join(dataPath, 'images', 'entries', 'posters'),
|
||||
'entry;logo': path.join(dataPath, 'images', 'entries', 'logos'),
|
||||
@@ -45,9 +43,10 @@ class MaintenanceService {
|
||||
|
||||
let missingFiles = [];
|
||||
for (let i = 0; i < allMedia.length; i++) {
|
||||
const folderType = `${allMedia[i].mediaable}${allMedia[i].type.replace("_preview", "")}`;
|
||||
const folderType = `${allMedia[i].mediaable};${allMedia[i].type.replace("_preview", "")}`;
|
||||
|
||||
if (!mediaTypeFolder[folderType]) continue;
|
||||
|
||||
if (!mediaTypeFolder[folderType]) continue
|
||||
const filePath = path.join(mediaTypeFolder[folderType], allMedia[i].path)
|
||||
if (!fs.existsSync(filePath)) {
|
||||
missingFiles.push(allMedia[i]);
|
||||
@@ -61,9 +60,6 @@ class MaintenanceService {
|
||||
'stills': 0,
|
||||
};
|
||||
|
||||
// if (missingFiles.length == 0)
|
||||
// return removed;
|
||||
|
||||
for (let i = 0; i < missingFiles.length; i++) {
|
||||
removed[missingFiles[i].type + 's'] += 1;
|
||||
if (!dry) missingFiles[i].destroy();
|
||||
@@ -82,7 +78,6 @@ class MaintenanceService {
|
||||
* @param {boolean} [dry=false] - if true only return the count of the files that are getting deleted, default=`false`
|
||||
*/
|
||||
async deleteOrphanFiles(dry = false) {
|
||||
// Getting the userDataPath to store the images
|
||||
const dataPath = _configService.getMediaFolder();
|
||||
|
||||
// ? Getting the name (without extention) of all media in database
|
||||
@@ -118,7 +113,7 @@ class MaintenanceService {
|
||||
try {
|
||||
// ? getting all files inside that folder
|
||||
const files = await fsPromises.readdir(directory).then();
|
||||
// console.log(`${directory}, files count: ${files.length}`);
|
||||
// console.log(`found ${files.length} files in ${directory}`);
|
||||
|
||||
// Check each file in the directory
|
||||
for (let file of files) {
|
||||
@@ -131,7 +126,7 @@ class MaintenanceService {
|
||||
if (!isInDatabase) {
|
||||
removed[folderType.split(';')[1] + 's']++; // Increment the count of removed files
|
||||
if (!dry) {
|
||||
const b = path.join(directory, file);
|
||||
const filePath = path.join(directory, file);
|
||||
await fsPromises.unlink(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user