From 612e27a55c75b5d5c37d1296c61b09c263000f6f Mon Sep 17 00:00:00 2001 From: "oscargonzalezmoreno@gmail.com" Date: Sat, 28 Dec 2024 12:48:32 +0100 Subject: [PATCH] fix user-agent update bug fix remove extra base64 encoding fix update http tests --- .gitignore | 2 +- package-lock.json | 3 +-- src/rices/rices.service.ts | 18 ++++++------------ test/restclient/01_create_rice.http | 2 +- test/restclient/02_download_rice.http | 2 +- test/restclient/03_update_rice.http | 6 ++---- 6 files changed, 12 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index ba7b630..20d19d5 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,7 @@ yarn-error.log* lerna-debug.log* #node -*package.lock +*package-lock.json # OS .DS_Store diff --git a/package-lock.json b/package-lock.json index 18ecbb2..387d0e7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3520,7 +3520,6 @@ ], "license": "MIT", "dependencies": { - "base64-js": "^1.3.1", "ieee754": "^1.1.13" } }, @@ -9793,4 +9792,4 @@ } } } -} +} \ No newline at end of file diff --git a/src/rices/rices.service.ts b/src/rices/rices.service.ts index f647f9f..b261d0c 100644 --- a/src/rices/rices.service.ts +++ b/src/rices/rices.service.ts @@ -94,8 +94,6 @@ export class RicesService { } const token = uuidv4(); - const encodedContent = Buffer.from(content).toString('base64'); - const metadata = { id: uuidv4(), token, @@ -115,7 +113,7 @@ export class RicesService { const uploadedFilePath = `rices/${slug}/data.zenrice`; await this.gitHubService.createOrUpdateFile( uploadedFilePath, - encodedContent, + content, `Add content to rice ${slug}`, ); @@ -139,13 +137,10 @@ export class RicesService { throw new NotFoundException('Rice file not found in GitHub'); } - // Decode Base64 content - const contentPrev = Buffer.from(fileContent, 'base64').toString('utf-8'); - // Remove unescaped double quotes at the beginning and end, if present - const content = contentPrev.replace(/^"|"$/g, ''); + // const content = contentPrev.replace(/^"|"$/g, ''); - return content; + return fileContent; } async update( @@ -156,11 +151,11 @@ export class RicesService { ) { try { // Extract fields from headers - const userAgent = headers['User-Agent']; + const userAgent = headers['user-agent']; if (!userAgent) { throw new BadRequestException( - 'Missing required headers: X-Zen-Rice-Name, X-Zen-Rice-Author, and User-Agent are mandatory.', + 'Missing required headers: User-Agent is mandatory.', ); } @@ -202,11 +197,10 @@ export class RicesService { await this.supabaseService.updateRice(slug, updatedMetadata); - const encodedContent = Buffer.from(content).toString('base64'); const uploadedFilePath = `rices/${slug}/data.zenrice`; await this.gitHubService.createOrUpdateFile( uploadedFilePath, - encodedContent, + content, `Update content in rice ${slug}`, ); diff --git a/test/restclient/01_create_rice.http b/test/restclient/01_create_rice.http index cd7ce87..92041a6 100644 --- a/test/restclient/01_create_rice.http +++ b/test/restclient/01_create_rice.http @@ -2,7 +2,7 @@ POST {{baseUrl}}/rices Content-Type: application/json -X-Zen-Rice-Name: cool-zenrice-aurora2 +X-Zen-Rice-Name: cool-zenrice-test-base64211 X-Zen-Rice-Author: jhon@doe.com User-Agent: ZenBrowser/1.2b.0 (EndeavourOS x86_64) diff --git a/test/restclient/02_download_rice.http b/test/restclient/02_download_rice.http index 94785fe..eb767dc 100644 --- a/test/restclient/02_download_rice.http +++ b/test/restclient/02_download_rice.http @@ -1,5 +1,5 @@ @baseUrl = http://localhost:3000 -@previous_slug = cool-zenrice-aurora2-4fe6417d-f901-43d2-92fc-720c6ed3e449 +@previous_slug = cool-zenrice-test-base64211-5f874c8c-71f7-4b45-830a-aa86c9328455 GET {{baseUrl}}/rices/{{previous_slug}} \ No newline at end of file diff --git a/test/restclient/03_update_rice.http b/test/restclient/03_update_rice.http index 8387318..1f388be 100644 --- a/test/restclient/03_update_rice.http +++ b/test/restclient/03_update_rice.http @@ -1,12 +1,10 @@ @baseUrl = http://localhost:3000 -@previous_slug = cool-zenrice-aurora2-4fe6417d-f901-43d2-92fc-720c6ed3e449 -@previous_token = e3ec0c0f-f455-4a4e-a06d-69d2e3bbf46c +@previous_slug = cool-zenrice-test-base64211-5f874c8c-71f7-4b45-830a-aa86c9328455 +@previous_token = 84780af0-191e-4f77-8c23-25165c89d27e PUT {{baseUrl}}/rices/{{previous_slug}} Content-Type: application/json x-zen-rices-token: {{previous_token}} -X-Zen-Rice-Name: cool-zenrice-aurora2 -X-Zen-Rice-Author: jhon@doe.com User-Agent: ZenBrowser/1.2b.0 (EndeavourOS x86_64) {