diff --git a/.vscode/launch.json b/.vscode/launch.json index 361da84..6d1d76e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,6 +10,32 @@ "localRoot": "${workspaceFolder}", "remoteRoot": "/usr/app", "skipFiles": ["/**"] + }, + { + "type": "node", + "request": "launch", + "name": "Debug Jest Tests", + "program": "${workspaceFolder}/node_modules/jest/bin/jest", + "args": [ + "--runInBand" + ], + "cwd": "${workspaceFolder}", + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest/bin/jest" + }, + "env": { + "NODE_ENV": "test" + }, + "sourceMaps": true, + "runtimeArgs": [ + "--experimental-vm-modules" + ], + "outFiles": [ + "${workspaceFolder}/dist/**/*.js" + ] } ] } diff --git a/package-lock.json b/package-lock.json index 841cfff..ab3ee91 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "UNLICENSED", "dependencies": { "@hiveio/dhive": "^1.1.0", - "@hiveio/hive-js": "^2.0.7", + "@hiveio/hive-js": "^2.0.8", "@magic-sdk/admin": "^2.1.0", "@nestjs/common": "^10.0.0", "@nestjs/config": "^3.2.2", @@ -3319,9 +3319,9 @@ } }, "node_modules/@hiveio/hive-js": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/@hiveio/hive-js/-/hive-js-2.0.7.tgz", - "integrity": "sha512-VBscrhbOm7BOCe9kmlltgpmw2NtxqJdhvdeQsO/fWfH5XK4uZjA8teFlcOu5OYg3FQq7+yDzbFhPPMp2Tctlbg==", + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/@hiveio/hive-js/-/hive-js-2.0.8.tgz", + "integrity": "sha512-SLOHVb0Xi7UDQu4ZfsJGsFfZhZZ5FSNdTg80uUp/CnGjqaeJwph8eAgJ2BhRIlpT4RR7W5tLyqfqaBefCwtw4A==", "dependencies": { "@steemit/rpc-auth": "^1.1.1", "bigi": "^1.4.2", diff --git a/package.json b/package.json index 0c7627c..2aa5e5f 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "type": "module", "dependencies": { "@hiveio/dhive": "^1.1.0", - "@hiveio/hive-js": "^2.0.7", + "@hiveio/hive-js": "^2.0.8", "@magic-sdk/admin": "^2.1.0", "@nestjs/common": "^10.0.0", "@nestjs/config": "^3.2.2", diff --git a/src/repositories/hive-chain/hive-chain.repository.spec.ts b/src/repositories/hive-chain/hive-chain.repository.spec.ts index 1a4e6b8..0f69b41 100644 --- a/src/repositories/hive-chain/hive-chain.repository.spec.ts +++ b/src/repositories/hive-chain/hive-chain.repository.spec.ts @@ -349,4 +349,16 @@ describe('HiveRepository', () => { expect(hiveRepository.verifyPostingAuth(account)).toBe(false); }) }) + + describe('hivePostExists', () => { + it('Returns true if the post exists', async () => { + const exists = await hiveRepository.hivePostExists({ author: 'sisygoboom', permlink: 'my-prayers-have-been-answered' }); + expect(exists).toBe(true); + }) + + it('Returns false if the post does not exist', async () => { + const exists = await hiveRepository.hivePostExists({ author: 'fake', permlink: 'pretend post' }); + expect(exists).toBe(false); + }) + }) }); diff --git a/src/repositories/hive-chain/hive-chain.repository.ts b/src/repositories/hive-chain/hive-chain.repository.ts index 33b350f..7bdc0f8 100644 --- a/src/repositories/hive-chain/hive-chain.repository.ts +++ b/src/repositories/hive-chain/hive-chain.repository.ts @@ -28,6 +28,7 @@ export class HiveChainRepository { readonly _hiveJs = hiveJsPackage; readonly _hive: Client = new Client( process.env.HIVE_HOST?.split(',') || [ + 'https://hive-api.web3telekom.xyz', 'https://anyx.io', 'https://hived.privex.io', 'https://rpc.ausbit.dev', @@ -62,7 +63,7 @@ export class HiveChainRepository { async hivePostExists({ author, permlink }: AuthorPerm): Promise { const fetchContent = async (): Promise => { - const content = await this._hiveJs.api.getContent(author, permlink); + const content = await this._hive.database.call('get_content', [author, permlink]); return typeof content === 'object' && !!content.body; }; diff --git a/src/services/auth/auth.controller.test.ts b/src/services/auth/auth.controller.test.ts index 3439695..2fdbd6f 100644 --- a/src/services/auth/auth.controller.test.ts +++ b/src/services/auth/auth.controller.test.ts @@ -206,31 +206,6 @@ describe('AuthController', () => { }) }) - it('Fails to log in when the user does not have posting authority', async () => { - const privateKey = PrivateKey.fromSeed(crypto.randomBytes(32).toString("hex")); - const message = { account: 'ned', ts: Date.now() }; - const signature = privateKey.sign(crypto.createHash('sha256').update(JSON.stringify(message)).digest()); - - process.env.TEST_PUBLIC_KEY = privateKey.createPublic().toString(); - - const body = { - authority_type: 'posting', - proof_payload: message, - proof: signature.toString(), - } - - return request(app.getHttpServer()) - .post('/v1/auth/login/singleton/hive') - .send(body) - .expect(401) - .then(response => { - expect(response.body).toEqual({ - errorType: "MISSING_POSTING_AUTHORITY", - reason: "Hive Account @ned has not granted posting authority to @threespeak" - }) - }) - }) - it('Fails to log in when the proof is out of date', async () => { const privateKey = PrivateKey.fromSeed(crypto.randomBytes(32).toString("hex")); const message = { account: 'starkerz', ts: 1984 }; diff --git a/src/services/auth/auth.controller.ts b/src/services/auth/auth.controller.ts index 01165ff..87832db 100644 --- a/src/services/auth/auth.controller.ts +++ b/src/services/auth/auth.controller.ts @@ -119,16 +119,6 @@ export class AuthController { ); } - if (!this.hiveRepository.verifyPostingAuth(accountDetails)) { - throw new HttpException( - { - reason: `Hive Account @${body.proof_payload.account} has not granted posting authority to @threespeak`, - errorType: 'MISSING_POSTING_AUTHORITY', - }, - HttpStatus.UNAUTHORIZED, - ); - } - return await this.authService.authenticateUser('singleton', body.proof_payload.account, 'hive'); } diff --git a/src/services/uploader/uploading.service.ts b/src/services/uploader/uploading.service.ts index a7e4520..5f4803a 100644 --- a/src/services/uploader/uploading.service.ts +++ b/src/services/uploader/uploading.service.ts @@ -1,4 +1,10 @@ -import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common'; +import { + BadRequestException, + Injectable, + Logger, + LoggerService, + NotFoundException, +} from '@nestjs/common'; import { VideoRepository } from '../../repositories/video/video.repository'; import { UploadRepository } from '../../repositories/upload/upload.repository'; import { PublishingService } from '../../services/publishing/publishing.service'; @@ -12,6 +18,8 @@ import { HiveService } from '../hive/hive.service'; @Injectable() export class UploadingService { + readonly #logger: LoggerService = new Logger(UploadingService.name); + constructor( private readonly uploadRepository: UploadRepository, private readonly videoRepository: VideoRepository, @@ -109,6 +117,7 @@ export class UploadingService { type: 'video', }); if (!uploadJob) { + this.#logger.error('The upload job could not be located'); throw new NotFoundException('The upload job could not be located'); } if (uploadJob.immediatePublish) { @@ -149,12 +158,15 @@ export class UploadingService { async handleTusdCallback(uploadMetaData: Upload) { if (uploadMetaData.authorization === 'TESTING') { + this.#logger.error('TestAuthorizationError'); throw new Error('TestAuthorizationError'); } if (uploadMetaData.Size >= 5000000000) { + this.#logger.error('File too big to be uploaded'); throw new Error('File too big to be uploaded'); } if (!uploadMetaData.Storage) { + this.#logger.error('Storage is undefined'); throw new Error('Storage is undefined'); } const info: ffmpeg.FfprobeData = await new Promise((resolve, reject) => { diff --git a/src/utils/exponentialBackoff.ts b/src/utils/exponentialBackoff.ts index 5dfa68b..e44bffe 100644 --- a/src/utils/exponentialBackoff.ts +++ b/src/utils/exponentialBackoff.ts @@ -1,7 +1,7 @@ export async function exponentialBackoff( fn: () => Promise, retries = 3, - delay = 1000, + delay = 500, ): Promise { for (let i = 0; i < retries; i++) { try {