Skip to content

Commit

Permalink
fix: import artwork gg drive
Browse files Browse the repository at this point in the history
  • Loading branch information
harisato committed Aug 5, 2024
1 parent 04bc6a1 commit c105289
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/modules/artwork/artwork.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Injectable,
InternalServerErrorException,
Logger,
OnModuleInit,
} from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { parse } from 'csv-parse/sync';
Expand All @@ -16,15 +17,24 @@ import { ArtworkGraphql } from './artwork.graphql';
import { generateSlug } from '../manga/util';

@Injectable()
export class ArtworkService {
export class ArtworkService implements OnModuleInit {
private readonly logger = new Logger(ArtworkService.name);
private googleService;

constructor(
private configService: ConfigService,
private fileService: FilesService,
private artworkGraphql: ArtworkGraphql
) {}

onModuleInit() {
const auth = new GoogleAuth({
scopes: 'https://www.googleapis.com/auth/drive',
keyFilename: this.configService.get<string>('google.analytics.keyFile'),
}) as any;
this.googleService = google.drive({ version: 'v3', auth });
}

async import(data: ImportArtworkDto, file: Express.Multer.File) {
const { token } = ContextProvider.getAuthUser();
const { contest_id, contest_round } = data;
Expand Down Expand Up @@ -143,15 +153,15 @@ export class ArtworkService {
}

private async crawlGoogleDriveImage(url: string) {
const auth = new GoogleAuth({
scopes: 'https://www.googleapis.com/auth/drive',
keyFilename: this.configService.get<string>('google.analytics.keyFile'),
}) as any;
const service = google.drive({ version: 'v3', auth });
// const auth = new GoogleAuth({
// scopes: 'https://www.googleapis.com/auth/drive',
// keyFilename: this.configService.get<string>('google.analytics.keyFile'),
// }) as any;
// const service = google.drive({ version: 'v3', auth });

const fileId = url.split('/')?.[5];
try {
const file = (await service.files.get(
const file = (await this.googleService.files.get(
{
fileId: fileId,
alt: 'media',
Expand All @@ -168,6 +178,7 @@ export class ArtworkService {
buffer,
};
} catch (error) {
this.logger.error(`cannot get image from url: ${url}`);
return {
errors: {
message: JSON.stringify(error),
Expand Down

0 comments on commit c105289

Please sign in to comment.