Skip to content

Commit

Permalink
feat: show public asset
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfulyang authored and powerfulyang committed Apr 2, 2024
1 parent dea0886 commit aa14e41
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 68 deletions.
66 changes: 6 additions & 60 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 13 additions & 7 deletions src/asset/asset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { AZUKI_ASSET_PATH, getBucketAssetPath } from '@/constants/asset_constant
import { ScheduleType } from '@/enum/ScheduleType';
import { getEXIF } from '@/lib/exif';
import { InstagramBotService } from '@/libs/instagram-bot';
import { PinterestBotService } from '@/libs/pinterest-bot';
import type { PinterestInterface } from '@/libs/pinterest-bot';
import { PinterestBotService } from '@/libs/pinterest-bot';
import { PixivBotService } from '@/libs/pixiv-bot';
import { ProxyFetchService } from '@/libs/proxy-fetch';
import { BaseService } from '@/service/base/BaseService';
Expand All @@ -30,11 +30,11 @@ import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
import { calculateHammingDistances, pHash, sha1 } from '@powerfulyang/node-utils';
import { firstItem, isArray, isNotNull, isNull, lastItem } from '@powerfulyang/utils';
import { ensureFileSync } from 'fs-extra';
import fetch from 'node-fetch';
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import sharp from 'sharp';
import { DataSource, In, Not, Repository } from 'typeorm';
import fetch from 'node-fetch';
import { join } from 'node:path';

@Injectable()
export class AssetService extends BaseService {
Expand Down Expand Up @@ -287,10 +287,13 @@ export class AssetService extends BaseService {
const undoes: PinterestInterface[] = await this.fetchUndoes(bucketName);

this.logger.info(`[${bucketName}]: undoes count is ${undoes.length}`);

const botUser = await this.userService.getAssetBotUser();

for (const undo of undoes.reverse()) {
this.logger.info(`[${bucketName}]: ${undo.id}\n${undo.imgList.join('\n')}`);
// check if the asset sn is already exist
const existingAsset = await this.assetDao.exist({
const existingAsset = await this.assetDao.exists({
where: {
sn: undo.id,
},
Expand All @@ -305,7 +308,7 @@ export class AssetService extends BaseService {

await this.processAsset(buffer, {
bucketName: bucket.name,
uploadBy: await this.userService.getAssetBotUser(),
uploadBy: botUser,
async: true,
assetAddition: {
sn: undo.id,
Expand All @@ -324,7 +327,7 @@ export class AssetService extends BaseService {
async infiniteQuery(params: InfiniteQueryParams<AuthorizationParams> = {}) {
const { userIds = [], prevCursor, nextCursor } = params;
const take = this.formatInfiniteTake(params.take);
const BotUser = await this.userService.getAssetBotUser();
const { publicBucketIds, publicUserIds } = await this.listPublicAssetSource();
const cursor = this.generateInfiniteCursor({
nextCursor,
prevCursor,
Expand All @@ -347,7 +350,10 @@ export class AssetService extends BaseService {
},
where: {
uploadBy: {
id: In(userIds.concat(BotUser.id)),
id: In(userIds.concat(publicUserIds)),
},
bucket: {
id: In(publicBucketIds),
},
id: cursor,
},
Expand Down
2 changes: 1 addition & 1 deletion src/fastify/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const createFastifyInstance = (): FastifyInstance => {
fastifyInstance.addHook('onSend', (_request, reply: FastifyReply, _payload, done) => {
// fix log.middleware.ts can't get response headers
reply.raw.setHeader('x-request-id', getRequestId() || '');
reply.header('x-process-time', `${reply.getResponseTime().toFixed(3)}ms`);
reply.header('x-process-time', `${reply.elapsedTime.toFixed(3)}ms`);
reply.header('x-server-id', HOSTNAME);
reply.header('x-server-time', DateTimeFormat());
done();
Expand Down

0 comments on commit aa14e41

Please sign in to comment.