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

@@ -96,7 +96,7 @@ module.exports = class Asset extends Model {
mime: opts.mimetype,
fileSize: opts.size,
folderId: opts.folderId,
authorId: opts.userId
authorId: opts.user.id
}
// Save asset data
@@ -119,20 +119,27 @@ module.exports = class Asset extends Model {
data: fileBuffer
})
}
// Move temp upload to cache
await fs.move(opts.path, path.join(process.cwd(), `data/cache/${fileHash}.dat`), { overwrite: true })
// Add to Storage
if (!opts.skipStorage) {
await WIKI.models.storage.assetEvent({
event: 'uploaded',
asset: {
...asset,
path: await asset.getAssetPath(),
data: fileBuffer,
authorId: opts.user.id,
authorName: opts.user.name,
authorEmail: opts.user.email
}
})
}
} catch (err) {
WIKI.logger.warn(err)
}
// Move temp upload to cache
await fs.move(opts.path, path.join(process.cwd(), `data/cache/${fileHash}.dat`), { overwrite: true })
// Add to Storage
if (!opts.skipStorage) {
await WIKI.models.storage.assetEvent({
event: 'uploaded',
asset
})
}
}
static async getAsset(assetPath, res) {