Merge branch 'fix/import-custom-emojis' into 'develop'
fix: #10451 Emoji pack imports randomly stop processing files Co-authored-by: Linca <lhcfllinca@gmail.com> Co-authored-by: Lhcfl <Lhcfl@outlook.com> Closes #10451 See merge request firefish/firefish!10757
This commit is contained in:
commit
d82ad33730
1 changed files with 33 additions and 4 deletions
|
@ -11,14 +11,28 @@ import { addFile } from "@/services/drive/add-file.js";
|
||||||
import { genId } from "backend-rs";
|
import { genId } from "backend-rs";
|
||||||
import { db } from "@/db/postgre.js";
|
import { db } from "@/db/postgre.js";
|
||||||
import probeImageSize from "probe-image-size";
|
import probeImageSize from "probe-image-size";
|
||||||
import * as path from "path";
|
import * as path from "node:path";
|
||||||
|
|
||||||
const logger = queueLogger.createSubLogger("import-custom-emojis");
|
const logger = queueLogger.createSubLogger("import-custom-emojis");
|
||||||
|
|
||||||
|
// probeImageSize acceptable extensions
|
||||||
|
// JPG, GIF, PNG, WebP, BMP, TIFF, SVG, PSD.
|
||||||
|
const acceptableExtensions = [
|
||||||
|
".jpeg",
|
||||||
|
".jpg",
|
||||||
|
".gif",
|
||||||
|
".png",
|
||||||
|
".webp",
|
||||||
|
".bmp",
|
||||||
|
// ".tiff", // Cannot be used as emoji
|
||||||
|
// ".svg", // Disable for secure issues
|
||||||
|
// ".psd", // Cannot be used as emoji
|
||||||
|
];
|
||||||
|
|
||||||
// TODO: 名前衝突時の動作を選べるようにする
|
// TODO: 名前衝突時の動作を選べるようにする
|
||||||
export async function importCustomEmojis(
|
export async function importCustomEmojis(
|
||||||
job: Bull.Job<DbUserImportJobData>,
|
job: Bull.Job<DbUserImportJobData>,
|
||||||
done: any,
|
done: () => void,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
logger.info("Importing custom emojis ...");
|
logger.info("Importing custom emojis ...");
|
||||||
|
|
||||||
|
@ -62,6 +76,14 @@ export async function importCustomEmojis(
|
||||||
if (!record.downloaded) continue;
|
if (!record.downloaded) continue;
|
||||||
const emojiInfo = record.emoji;
|
const emojiInfo = record.emoji;
|
||||||
const emojiPath = `${outputPath}/${record.fileName}`;
|
const emojiPath = `${outputPath}/${record.fileName}`;
|
||||||
|
|
||||||
|
const extname = path.extname(record.fileName);
|
||||||
|
|
||||||
|
// Skip non-support files
|
||||||
|
if (!acceptableExtensions.includes(extname.toLowerCase())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
await Emojis.delete({
|
await Emojis.delete({
|
||||||
name: emojiInfo.name,
|
name: emojiInfo.name,
|
||||||
});
|
});
|
||||||
|
@ -92,7 +114,7 @@ export async function importCustomEmojis(
|
||||||
} else {
|
} else {
|
||||||
logger.info("starting emoji import without metadata");
|
logger.info("starting emoji import without metadata");
|
||||||
// Since we lack metadata, we import into a randomized category name instead
|
// Since we lack metadata, we import into a randomized category name instead
|
||||||
let categoryName = genId();
|
const categoryName = genId();
|
||||||
|
|
||||||
let containedEmojis = fs.readdirSync(outputPath);
|
let containedEmojis = fs.readdirSync(outputPath);
|
||||||
|
|
||||||
|
@ -103,7 +125,14 @@ export async function importCustomEmojis(
|
||||||
|
|
||||||
for (const emojiFilename of containedEmojis) {
|
for (const emojiFilename of containedEmojis) {
|
||||||
// strip extension and get filename to use as name
|
// strip extension and get filename to use as name
|
||||||
const name = path.basename(emojiFilename, path.extname(emojiFilename));
|
const extname = path.extname(emojiFilename);
|
||||||
|
|
||||||
|
// Skip non-emoji files, such as LICENSE
|
||||||
|
if (!acceptableExtensions.includes(extname.toLowerCase())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = path.basename(emojiFilename, extname);
|
||||||
const emojiPath = `${outputPath}/${emojiFilename}`;
|
const emojiPath = `${outputPath}/${emojiFilename}`;
|
||||||
|
|
||||||
logger.info(`importing ${name}`);
|
logger.info(`importing ${name}`);
|
||||||
|
|
Loading…
Reference in a new issue