mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
feat: update DB schema to use subscriber.avatar
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Hexastack. All rights reserved.
|
||||
* Copyright © 2025 Hexastack. All rights reserved.
|
||||
*
|
||||
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||
@@ -28,6 +28,7 @@ import { Request } from 'express';
|
||||
import { Session as ExpressSession } from 'express-session';
|
||||
|
||||
import { AttachmentService } from '@/attachment/services/attachment.service';
|
||||
import { config } from '@/config';
|
||||
import { CsrfInterceptor } from '@/interceptors/csrf.interceptor';
|
||||
import { LoggerService } from '@/logger/logger.service';
|
||||
import { Roles } from '@/utils/decorators/roles.decorator';
|
||||
@@ -83,7 +84,7 @@ export class ReadOnlyUserController extends BaseController<
|
||||
*/
|
||||
@Roles('public')
|
||||
@Get('bot/profile_pic')
|
||||
async botProfilePic(@Query('color') color: string) {
|
||||
async getBotAvatar(@Query('color') color: string) {
|
||||
return await getBotAvatar(color);
|
||||
}
|
||||
|
||||
@@ -96,18 +97,20 @@ export class ReadOnlyUserController extends BaseController<
|
||||
*/
|
||||
@Roles('public')
|
||||
@Get(':id/profile_pic')
|
||||
async UserProfilePic(@Param('id') id: string) {
|
||||
try {
|
||||
const res = await this.userService.userProfilePic(id);
|
||||
return res;
|
||||
} catch (e) {
|
||||
const user = await this.userService.findOne(id);
|
||||
if (user) {
|
||||
return await generateInitialsAvatar(user);
|
||||
} else {
|
||||
throw new NotFoundException(`user with ID ${id} not found`);
|
||||
}
|
||||
async getAvatar(@Param('id') id: string) {
|
||||
const user = await this.userService.findOneAndPopulate(id);
|
||||
if (!user) {
|
||||
throw new NotFoundException(`user with ID ${id} not found`);
|
||||
}
|
||||
|
||||
if (user.avatar) {
|
||||
return await this.attachmentService.download(
|
||||
user.avatar,
|
||||
config.parameters.avatarDir,
|
||||
);
|
||||
}
|
||||
|
||||
return generateInitialsAvatar(user);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
/*
|
||||
* Copyright © 2024 Hexastack. All rights reserved.
|
||||
* Copyright © 2025 Hexastack. All rights reserved.
|
||||
*
|
||||
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||
* 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 { join } from 'path';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { Injectable, NotFoundException, StreamableFile } from '@nestjs/common';
|
||||
|
||||
import { getStreamableFile } from '@/attachment/utilities';
|
||||
import { config } from '@/config';
|
||||
import { BaseService } from '@/utils/generics/base-service';
|
||||
|
||||
import { UserRepository } from '../repositories/user.repository';
|
||||
@@ -22,33 +18,4 @@ export class UserService extends BaseService<User, UserPopulate, UserFull> {
|
||||
constructor(readonly repository: UserRepository) {
|
||||
super(repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the user's profile picture as a streamable file.
|
||||
*
|
||||
* @param id - The ID of the user whose profile picture is requested.
|
||||
*
|
||||
* @returns A promise that resolves with the streamable file of the user's profile picture.
|
||||
*/
|
||||
async userProfilePic(id: string): Promise<StreamableFile> {
|
||||
const user = await this.findOneAndPopulate(id);
|
||||
if (user) {
|
||||
const attachment = user.avatar;
|
||||
const path = join(config.parameters.uploadDir, attachment.location);
|
||||
const disposition = `attachment; filename="${encodeURIComponent(
|
||||
attachment.name,
|
||||
)}"`;
|
||||
|
||||
return getStreamableFile({
|
||||
path,
|
||||
options: {
|
||||
type: attachment.type,
|
||||
length: attachment.size,
|
||||
disposition,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
throw new NotFoundException('Profile Not found');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user