-
-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add robot and anonymous display (#1110)
* feat: add robot and anonymous display * fix: core test * Fix code scanning alert no. 27: Client-side cross-site scripting * fix: ignore 1pass in field name * fix: copy overlap in cell * feat: prevent auto new options on select field * fix: redirect risk * fix: test --------- Signed-off-by: Bieber <[email protected]>
- Loading branch information
1 parent
1e6e4e1
commit 5adcc8b
Showing
45 changed files
with
476 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
apps/nestjs-backend/src/features/user/user-init.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { join, resolve } from 'path'; | ||
import { Injectable, Logger, type OnModuleInit } from '@nestjs/common'; | ||
import { PrismaService } from '@teable/db-main-prisma'; | ||
import { UploadType } from '@teable/openapi'; | ||
import { createReadStream } from 'fs-extra'; | ||
import sharp from 'sharp'; | ||
import StorageAdapter from '../attachments/plugins/adapter'; | ||
import { InjectStorageAdapter } from '../attachments/plugins/storage'; | ||
|
||
@Injectable() | ||
export class UserInitService implements OnModuleInit { | ||
private logger = new Logger(UserInitService.name); | ||
|
||
constructor( | ||
private readonly prismaService: PrismaService, | ||
@InjectStorageAdapter() readonly storageAdapter: StorageAdapter | ||
) {} | ||
|
||
async onModuleInit() { | ||
await this.uploadStatic( | ||
'automationRobot', | ||
'static/system/automation-robot.png', | ||
UploadType.Avatar | ||
); | ||
await this.uploadStatic('anonymous', 'static/system/anonymous.png', UploadType.Avatar); | ||
|
||
this.logger.log('System users initialized'); | ||
} | ||
|
||
async uploadStatic(id: string, filePath: string, type: UploadType) { | ||
const fileStream = createReadStream(resolve(process.cwd(), filePath)); | ||
const metaReader = sharp(); | ||
const sharpReader = fileStream.pipe(metaReader); | ||
const { width, height, format = 'png', size = 0 } = await sharpReader.metadata(); | ||
const path = join(StorageAdapter.getDir(type), id); | ||
const bucket = StorageAdapter.getBucket(type); | ||
const mimetype = `image/${format}`; | ||
const { hash } = await this.storageAdapter.uploadFileWidthPath(bucket, path, filePath, { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
'Content-Type': mimetype, | ||
}); | ||
await this.prismaService.txClient().attachments.upsert({ | ||
create: { | ||
token: id, | ||
path, | ||
size, | ||
width, | ||
height, | ||
hash, | ||
mimetype, | ||
createdBy: 'system', | ||
}, | ||
update: { | ||
size, | ||
width, | ||
height, | ||
hash, | ||
mimetype, | ||
lastModifiedBy: 'system', | ||
}, | ||
where: { | ||
token: id, | ||
deletedTime: null, | ||
}, | ||
}); | ||
return `/${path}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.