fix custom emoji
This commit is contained in:
@@ -17,59 +17,17 @@ module.exports = async function (context) {
|
||||
while (await cursor.hasNext()) {
|
||||
const result = await cursor.next()
|
||||
|
||||
// Prepare destination file
|
||||
const filename = `${result.name}.${result.extension}`
|
||||
const dest = `${context.config.target.filesPath}/custom_emoji/${filename}`
|
||||
// Download emoji file
|
||||
if (result.store.startsWith('FileSystem:')) {
|
||||
const src = context.config.source.customEmojiPath
|
||||
const srcFilename = Utils.srcPath(src, filename)
|
||||
if (!srcFilename) {
|
||||
return new Error(`source file "${filename}" not found`)
|
||||
}
|
||||
// Copy to output dir
|
||||
|
||||
const srcFilename = Utils.srcPath(context.config.source.customEmojiPath, filename)
|
||||
if (srcFilename) {
|
||||
Utils.copyFile(srcFilename, dest)
|
||||
} else if (result.store.startsWith('GridFS:')) {
|
||||
await Utils.downloadGridFS(context, fileCollection, filename, dest)
|
||||
} else {
|
||||
throw new Error(`file system ${file.store} is not supported. Migrate to FileSystem first, see readme.`)
|
||||
await Utils.downloadGridFSByName(context, fileCollection, filename, dest)
|
||||
}
|
||||
|
||||
// Export custom emoji
|
||||
let emoji = {
|
||||
name: result.name,
|
||||
image: dest,
|
||||
}
|
||||
log.info(`... writing ${emoji.name}`)
|
||||
context.output.write(
|
||||
Factory.emoji(emoji)
|
||||
)
|
||||
log.info(`... copied ${result.name}`)
|
||||
}
|
||||
return context
|
||||
}
|
||||
|
||||
const exportFile = async function (context, collection, fileId) {
|
||||
const type = collection.collectionName
|
||||
const file = await collection.findOne({ _id: fileId })
|
||||
if (!file) {
|
||||
throw new Error(`file ${fileId} from collection ${type} is missing`)
|
||||
}
|
||||
const dest = context.config.target.filesPath
|
||||
const destFilename = utils.destPath(dest, collection.collectionName, file)
|
||||
|
||||
if (file.store.startsWith('FileSystem:')) {
|
||||
const src = context.config.source.uploadsPath
|
||||
const srcFilename = utils.srcPath(src, file._id)
|
||||
if (!srcFilename) {
|
||||
return new Error(`source file "${file._id}" not found`)
|
||||
}
|
||||
// Copy to output dir
|
||||
utils.copyFile(srcFilename, destFilename)
|
||||
} else if (file.store.startsWith('GridFS:')) {
|
||||
await utils.downloadGridFS(context, collection, file._id, destFilename)
|
||||
} else {
|
||||
throw new Error(`file system ${file.store} is not supported. Migrate to FileSystem first, see readme.`)
|
||||
}
|
||||
|
||||
return destFilename
|
||||
}
|
||||
Reference in New Issue
Block a user