feat: asset add/rename/remove + dump action for git and disk modules

This commit is contained in:
NGPixel
2019-10-19 17:39:45 -04:00
parent 73aa870abc
commit d987058336
7 changed files with 128 additions and 30 deletions

View File

@@ -39,7 +39,7 @@ module.exports = class AssetFolder extends Model {
*
* @param {Number} folderId Id of the folder
*/
static async getHierarchy(folderId) {
static async getHierarchy (folderId) {
const hier = await WIKI.models.knex.withRecursive('ancestors', qb => {
qb.select('id', 'name', 'slug', 'parentId').from('assetFolders').where('id', folderId).union(sqb => {
sqb.select('a.id', 'a.name', 'a.slug', 'a.parentId').from('assetFolders AS a').join('ancestors', 'ancestors.parentId', 'a.id')
@@ -48,4 +48,22 @@ module.exports = class AssetFolder extends Model {
// The ancestors are from children to grandparents, must reverse for correct path order.
return _.reverse(hier)
}
/**
* Get full folder paths
*/
static async getAllPaths () {
const all = await WIKI.models.assetFolders.query()
let folders = {}
all.forEach(fld => {
_.set(folders, fld.id, fld.slug)
let parentId = fld.parentId
while (parentId !== null || parentId > 0) {
const parent = _.find(all, ['id', parentId])
_.set(folders, fld.id, `${parent.slug}/${_.get(folders, fld.id)}`)
parentId = parent.parentId
}
})
return folders
}
}