Skip to content

Commit

Permalink
Add back graphUpload
Browse files Browse the repository at this point in the history
  • Loading branch information
danielailie committed Sep 11, 2023
1 parent cfc1684 commit 26de831
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 23 deletions.
90 changes: 90 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"graphql-query-complexity": "0.12.0",
"graphql-relay": "0.10.0",
"graphql-tools": "8.3.18",
"graphql-upload": "13.0.0",
"helmet": "4.4.1",
"jwks-rsa": "2.0.3",
"moment": "^2.29.4",
Expand Down
8 changes: 6 additions & 2 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -966,8 +966,8 @@ type Mutation {
clearReportCollection(input: ClearReportCollectionInput!): Boolean!
clearReportNft(input: ClearReportInput!): Boolean!
createAuction(input: CreateAuctionArgs!): TransactionNode!
createNft(input: CreateNftArgs!): TransactionNode!
createNftWithMultipleFiles(input: CreateNftArgs!): TransactionNode!
createNft(file: Upload!, input: CreateNftArgs!): TransactionNode!
createNftWithMultipleFiles(files: [Upload!]!, input: CreateNftArgs!): TransactionNode!
deployMinter(input: DeployMinterArgs!): TransactionNode!
endAuction(auctionId: Int!): TransactionNode!
flagCollection(input: FlagCollectionInput!): Boolean!
Expand Down Expand Up @@ -1001,6 +1001,7 @@ type Mutation {
upgradeNftRoyalties(input: UpgradeNftArgs!): TransactionNode!
validateCollectionRarities(collectionTicker: String!): Boolean!
validateOrUpdateNftScamInfo(identifier: String!): Boolean!
verifyContent(file: Upload!): Boolean!
whitelistCollectionOnMarketplace(input: WhitelistCollectionArgs!): Boolean!
whitelistMinter(input: WhitelistMinterArgs!): Boolean!
withdraw(auctionId: Int!): TransactionNode!
Expand Down Expand Up @@ -1532,6 +1533,9 @@ input UpgradeNftArgs {
minterAddress: String!
}

"""The `Upload` scalar type represents a file upload."""
scalar Upload

input WhitelistCollectionArgs {
collection: String!
marketplaceKey: String!
Expand Down
1 change: 0 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import { MintersModuleGraph } from './modules/minters/minters.module';
driver: ApolloDriver,
imports: [CommonModule],
useFactory: async () => ({
headers: { 'Apollo-Require-Preflight': true },
autoSchemaFile: 'schema.gql',
introspection: process.env.NODE_ENV !== 'production',
playground: false,
Expand Down
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ElasticTraitsUpdaterModule } from './crons/elastic.updater/elastic-trai
import { ElasticNftScamUpdaterModule } from './crons/elastic.updater/elastic-scam.updater.module';
import { ports } from './config';
import { LoggerService } from './utils/LoggerService';
import { graphqlUploadExpress } from 'graphql-upload';
import { PubSubListenerModule } from './pubsub/pub.sub.listener.module';
import { ApiConfigModule } from './modules/common/api-config/api.config.module';
import { ApiConfigService } from './modules/common/api-config/api.config.service';
Expand Down Expand Up @@ -116,7 +117,8 @@ async function startPublicApp() {
const app = await NestFactory.create(AppModule, {
logger: new LoggerService(),
});
// app.use(graphqlUploadExpress({ headers: { 'Apollo-Require-Preflight': 'true' } }));
app.enableCors();
app.use(graphqlUploadExpress());

const httpAdapterHostService = app.get<HttpAdapterHost>(HttpAdapterHost);

Expand Down
27 changes: 14 additions & 13 deletions src/modules/assets/assets-mutations.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Resolver, Args, Mutation } from '@nestjs/graphql';
import { BaseResolver } from '../common/base.resolver';
import { AssetsTransactionService } from '.';
import { Asset, CreateNftArgs, TransferNftArgs, HandleQuantityArgs, AddLikeArgs, RemoveLikeArgs } from './models';
import { GraphQLUpload, FileUpload } from 'graphql-upload';
import { AssetsLikesService } from './assets-likes.service';
import { UseGuards } from '@nestjs/common';
import { ContentValidation } from './content.validation.service';
Expand All @@ -26,7 +27,7 @@ export class AssetsMutationsResolver extends BaseResolver(Asset) {
@UseGuards(JwtOrNativeAuthGuard)
async createNft(
@Args('input', { type: () => CreateNftArgs }) input: CreateNftArgs,
// @Args({ name: 'file', type: () => GraphQLUpload }) file: FileUpload,
@Args({ name: 'file', type: () => GraphQLUpload }) file: FileUpload,
@AuthUser() user: UserAuthResult,
): Promise<TransactionNode> {
const request = CreateNftRequest.fromArgs(input, 'file');
Expand All @@ -37,24 +38,24 @@ export class AssetsMutationsResolver extends BaseResolver(Asset) {
@UseGuards(JwtOrNativeAuthGuard)
async createNftWithMultipleFiles(
@Args('input', { type: () => CreateNftArgs }) input: CreateNftArgs,
// @Args({ name: 'files', type: () => [GraphQLUpload] }) files: [FileUpload],
@Args({ name: 'files', type: () => [GraphQLUpload] }) files: [FileUpload],
@AuthUser() user: UserAuthResult,
): Promise<TransactionNode> {
const request = CreateNftWithMultipleFilesRequest.fromArgs(input, ['files']);
const request = CreateNftWithMultipleFilesRequest.fromArgs(input, files);
return await this.assetsTransactionService.createNftWithMultipleFiles(user.address, request);
}

// @Mutation(() => Boolean)
// @UseGuards(JwtOrNativeAuthGuard)
// async verifyContent(@Args({ name: 'file', type: () => GraphQLUpload }) file: FileUpload): Promise<Boolean> {
// const fileData = await file;
@Mutation(() => Boolean)
@UseGuards(JwtOrNativeAuthGuard)
async verifyContent(@Args({ name: 'file', type: () => GraphQLUpload }) file: FileUpload): Promise<Boolean> {
const fileData = await file;

// const contentStatus = (await this.contentValidation.checkContentType(fileData).checkContentSensitivity(fileData)).getStatus();
// if (contentStatus) {
// return true;
// }
// throw Error('Invalid content');
// }
const contentStatus = (await this.contentValidation.checkContentType(fileData).checkContentSensitivity(fileData)).getStatus();
if (contentStatus) {
return true;
}
throw Error('Invalid content');
}

@Mutation(() => TransactionNode)
@UseGuards(JwtOrNativeAuthGuard)
Expand Down
5 changes: 3 additions & 2 deletions src/modules/assets/assets-transaction.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, AddressValue, BytesValue, ContractFunction, TokenTransfer, U64Value } from '@multiversx/sdk-core';
import { Address, AddressValue, BytesValue, ContractFunction, U64Value } from '@multiversx/sdk-core';
import { Injectable, Logger, NotFoundException } from '@nestjs/common';
import { MxApiService, getSmartContract } from 'src/common';
import { mxConfig, gas } from 'src/config';
Expand All @@ -12,6 +12,7 @@ import BigNumber from 'bignumber.js';
import { TransactionNode } from '../common/transaction';
import { UpdateQuantityRequest, CreateNftRequest, TransferNftRequest, CreateNftWithMultipleFilesRequest } from './models/requests';
import { generateCacheKeyFromParams } from 'src/utils/generate-cache-key';
import { FileUpload } from 'graphql-upload';
import { MxStats } from 'src/common/services/mx-communication/models/mx-stats.model';
import { RedisCacheService } from '@multiversx/sdk-nestjs-cache';
import { Constants } from '@multiversx/sdk-nestjs-common';
Expand Down Expand Up @@ -142,7 +143,7 @@ export class AssetsTransactionService {
return assetMetadata;
}

private async uploadFileToPinata(fileUpload: any) {
private async uploadFileToPinata(fileUpload: FileUpload) {
const file = await fileUpload;
const fileData = await this.pinataService.uploadFile(file);
await this.s3Service.upload(file, fileData.hash);
Expand Down
9 changes: 5 additions & 4 deletions src/modules/assets/models/requests/CreateNftRequest.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FileUpload } from 'graphql-upload';
import { CreateNftArgs } from '../CreateNftArgs';

export class CreateNftRequest {
Expand All @@ -6,13 +7,13 @@ export class CreateNftRequest {
name: string;
royalties: string = '0';
attributes: Attribute;
file: any;
file: FileUpload;

constructor(init?: Partial<CreateNftRequest>) {
Object.assign(this, init);
}

static fromArgs(nftArgs: CreateNftArgs, file: any) {
static fromArgs(nftArgs: CreateNftArgs, file: FileUpload) {
return new CreateNftRequest({
collection: nftArgs.collection,
quantity: nftArgs.quantity,
Expand All @@ -38,13 +39,13 @@ export class CreateNftWithMultipleFilesRequest {
name: string;
royalties: string = '0';
attributes: Attribute;
files: any[];
files: FileUpload[];

constructor(init?: Partial<CreateNftWithMultipleFilesRequest>) {
Object.assign(this, init);
}

static fromArgs(nftArgs: CreateNftArgs, files: any[]) {
static fromArgs(nftArgs: CreateNftArgs, files: FileUpload[]) {
return new CreateNftWithMultipleFilesRequest({
collection: nftArgs.collection,
quantity: nftArgs.quantity,
Expand Down

0 comments on commit 26de831

Please sign in to comment.