mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: avatar dir
This commit is contained in:
@@ -6,12 +6,16 @@
|
||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||
*/
|
||||
|
||||
import { existsSync, promises as fsPromises } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
import attachmentSchema, {
|
||||
Attachment,
|
||||
} from '@/attachment/schemas/attachment.schema';
|
||||
import subscriberSchema, { Subscriber } from '@/chat/schemas/subscriber.schema';
|
||||
import { config } from '@/config';
|
||||
|
||||
import { MigrationServices } from '../types';
|
||||
|
||||
@@ -74,13 +78,37 @@ const unpopulateSubscriberAvatar = async ({ logger }: MigrationServices) => {
|
||||
}
|
||||
};
|
||||
|
||||
const updateOldAvatarsPath = async ({ logger }: MigrationServices) => {
|
||||
const oldPath = join(process.cwd(), process.env.AVATAR_DIR || '/avatars');
|
||||
if (existsSync(oldPath)) {
|
||||
await fsPromises.copyFile(oldPath, config.parameters.avatarDir);
|
||||
await fsPromises.unlink(oldPath);
|
||||
logger.log('Avatars folder successfully moved to its new location ...');
|
||||
} else {
|
||||
logger.log('No old avatars folder found ...');
|
||||
}
|
||||
};
|
||||
|
||||
const restoreOldAvatarsPath = async ({ logger }: MigrationServices) => {
|
||||
const oldPath = join(process.cwd(), process.env.AVATAR_DIR || '/avatars');
|
||||
if (existsSync(config.parameters.avatarDir)) {
|
||||
await fsPromises.copyFile(config.parameters.avatarDir, oldPath);
|
||||
await fsPromises.unlink(config.parameters.avatarDir);
|
||||
logger.log('Avatars folder successfully moved to its old location ...');
|
||||
} else {
|
||||
logger.log('No avatars folder found ...');
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
async up(services: MigrationServices) {
|
||||
await populateSubscriberAvatar(services);
|
||||
await updateOldAvatarsPath(services);
|
||||
return true;
|
||||
},
|
||||
async down(services: MigrationServices) {
|
||||
await unpopulateSubscriberAvatar(services);
|
||||
await restoreOldAvatarsPath(services);
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user