mirror of
https://github.com/strapi/strapi.git
synced 2025-07-22 16:37:13 +00:00
29 lines
651 B
JavaScript
29 lines
651 B
JavaScript
'use strict';
|
|
|
|
const { FOLDER_MODEL_UID, FILE_MODEL_UID } = require('../constants');
|
|
|
|
const { getService } = require('../utils');
|
|
|
|
const getFolderPath = async (folderId) => {
|
|
if (!folderId) return '/';
|
|
|
|
const parentFolder = await strapi.entityService.findOne(FOLDER_MODEL_UID, folderId);
|
|
|
|
return parentFolder.path;
|
|
};
|
|
|
|
const deleteByIds = async (ids = []) => {
|
|
const filesToDelete = await strapi.db
|
|
.query(FILE_MODEL_UID)
|
|
.findMany({ where: { id: { $in: ids } } });
|
|
|
|
await Promise.all(filesToDelete.map((file) => getService('upload').remove(file)));
|
|
|
|
return filesToDelete;
|
|
};
|
|
|
|
module.exports = {
|
|
getFolderPath,
|
|
deleteByIds,
|
|
};
|