Skip to content

Commit

Permalink
build: 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 0404e49
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 80 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v3
with:
version: latest
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
Expand All @@ -36,7 +36,7 @@ jobs:
run: pnpm install
- name: Get number of CPU cores
id: cpu-cores
uses: SimenB/github-actions-cpu-cores@v1
uses: SimenB/github-actions-cpu-cores@v2
- name: Test
run: pnpm run test:unit --max-workers ${{ steps.cpu-cores.outputs.count }}
- name: TSC check
Expand All @@ -56,15 +56,15 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
Expand Down
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.

33 changes: 22 additions & 11 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 @@ -345,12 +348,20 @@ export class AssetService extends BaseService {
},
alt: true,
},
where: {
uploadBy: {
id: In(userIds.concat(BotUser.id)),
where: [
{
uploadBy: {
id: In(userIds.concat(publicUserIds)),
},
id: cursor,
},
id: cursor,
},
{
bucket: {
id: In(publicBucketIds),
},
id: cursor,
},
],
order: {
id: 'DESC',
},
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 0404e49

Please sign in to comment.