fix: upload file hash order
This commit is contained in:
parent
eedd1c0707
commit
1fecf38034
@ -87,7 +87,7 @@ router.post('/u', multer({
|
|||||||
...fileMeta,
|
...fileMeta,
|
||||||
originalname: sanitize(fileMeta.originalname).toLowerCase(),
|
originalname: sanitize(fileMeta.originalname).toLowerCase(),
|
||||||
folderId: folderId,
|
folderId: folderId,
|
||||||
hierarchy,
|
assetPath,
|
||||||
userId: req.user.id
|
userId: req.user.id
|
||||||
})
|
})
|
||||||
res.send('ok')
|
res.send('ok')
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* global WIKI */
|
|
||||||
|
|
||||||
const Model = require('objection').Model
|
const Model = require('objection').Model
|
||||||
|
const _ = require('lodash')
|
||||||
|
|
||||||
|
/* global WIKI */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Users model
|
* Users model
|
||||||
@ -33,11 +34,18 @@ module.exports = class AssetFolder extends Model {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get full folder hierarchy starting from specified folder to root
|
||||||
|
*
|
||||||
|
* @param {Number} folderId Id of the folder
|
||||||
|
*/
|
||||||
static async getHierarchy(folderId) {
|
static async getHierarchy(folderId) {
|
||||||
return WIKI.models.knex.withRecursive('ancestors', qb => {
|
const hier = await WIKI.models.knex.withRecursive('ancestors', qb => {
|
||||||
qb.select('id', 'name', 'slug', 'parentId').from('assetFolders').where('id', folderId).union(sqb => {
|
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')
|
sqb.select('a.id', 'a.name', 'a.slug', 'a.parentId').from('assetFolders AS a').join('ancestors', 'ancestors.parentId', 'a.id')
|
||||||
})
|
})
|
||||||
}).select('*').from('ancestors')
|
}).select('*').from('ancestors')
|
||||||
|
// The ancestors are from children to grandparents, must reverse for correct path order.
|
||||||
|
return _.reverse(hier)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,8 +67,7 @@ module.exports = class Asset extends Model {
|
|||||||
|
|
||||||
static async upload(opts) {
|
static async upload(opts) {
|
||||||
const fileInfo = path.parse(opts.originalname)
|
const fileInfo = path.parse(opts.originalname)
|
||||||
const folderPath = opts.hierarchy.map(h => h.slug).join('/')
|
const fileHash = assetHelper.generateHash(opts.assetPath)
|
||||||
const fileHash = opts.folderId ? assetHelper.generateHash(`${folderPath}/${opts.originalname}`) : assetHelper.generateHash(opts.originalname)
|
|
||||||
|
|
||||||
// Create asset entry
|
// Create asset entry
|
||||||
const asset = await WIKI.models.assets.query().insert({
|
const asset = await WIKI.models.assets.query().insert({
|
||||||
|
Loading…
Reference in New Issue
Block a user