From 59ed2326bb0e7eddd0c335bd350e522f1f5b77fe Mon Sep 17 00:00:00 2001 From: ClaudiaFang Date: Sat, 25 Apr 2026 20:18:09 +0000 Subject: [PATCH 1/2] fix: remove commend --- src/services/github-service.ts | 1 - src/services/gitlab-service.ts | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/services/github-service.ts b/src/services/github-service.ts index a87843f..3074c1f 100644 --- a/src/services/github-service.ts +++ b/src/services/github-service.ts @@ -1,4 +1,3 @@ -/* global Buffer */ import { requestUrl, RequestUrlResponse, RequestUrlParam } from 'obsidian'; import { GitServiceInterface } from './git-service-interface'; diff --git a/src/services/gitlab-service.ts b/src/services/gitlab-service.ts index 9442fcf..0879a6a 100644 --- a/src/services/gitlab-service.ts +++ b/src/services/gitlab-service.ts @@ -1,4 +1,4 @@ -/* global Buffer */ + import { requestUrl, RequestUrlResponse, RequestUrlParam } from 'obsidian'; import { GitServiceInterface } from './git-service-interface'; @@ -58,7 +58,7 @@ export class GitLabService implements GitServiceInterface { const status = error.status || 0; const responseData = error.response; const text = responseData?.text || (responseData?.json ? JSON.stringify(responseData.json) : ''); - + // Re-throw as a standardized response-like object if it looks like one if (status) { return { From 9ff423925bcdaa1f84041854f1f977ea048e423a Mon Sep 17 00:00:00 2001 From: ClaudiaFang Date: Sat, 25 Apr 2026 20:24:53 +0000 Subject: [PATCH 2/2] fix: replace Buffer with Web APIs to resolve lint errors --- src/services/github-service.ts | 22 ++++++++++++++++++++-- src/services/gitlab-service.ts | 22 ++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/services/github-service.ts b/src/services/github-service.ts index 3074c1f..2ce2f12 100644 --- a/src/services/github-service.ts +++ b/src/services/github-service.ts @@ -87,7 +87,7 @@ export class GitHubService implements GitServiceInterface { } const data = (response.json as unknown) as GitHubFileResponse; - const decodedContent = Buffer.from(data.content, 'base64').toString('utf8'); + const decodedContent = this.fromBase64(data.content); return { content: decodedContent, @@ -102,7 +102,7 @@ export class GitHubService implements GitServiceInterface { const body: Record = { message: commitMessage, - content: Buffer.from(content, 'utf8').toString('base64'), + content: this.toBase64(content), branch }; @@ -265,4 +265,22 @@ export class GitHubService implements GitServiceInterface { .filter(item => item.type === 'blob' && item.path.endsWith('.gitignore')) .map(item => item.path); } + + private toBase64(str: string): string { + const bytes = new TextEncoder().encode(str); + let binary = ''; + bytes.forEach((byte) => { + binary += String.fromCharCode(byte); + }); + return btoa(binary); + } + + private fromBase64(base64: string): string { + const binary = atob(base64.replace(/\s/g, '')); + const bytes = new Uint8Array(binary.length); + for (let i = 0; i < binary.length; i++) { + bytes[i] = binary.charCodeAt(i); + } + return new TextDecoder().decode(bytes); + } } diff --git a/src/services/gitlab-service.ts b/src/services/gitlab-service.ts index 0879a6a..1e785f6 100644 --- a/src/services/gitlab-service.ts +++ b/src/services/gitlab-service.ts @@ -94,7 +94,7 @@ export class GitLabService implements GitServiceInterface { } const data = (response.json as unknown) as GitLabFileResponse; - const decodedContent = Buffer.from(data.content, 'base64').toString('utf8'); + const decodedContent = this.fromBase64(data.content); return { content: decodedContent, @@ -118,7 +118,7 @@ export class GitLabService implements GitServiceInterface { body: JSON.stringify({ branch, commit_message: commitMessage, - content: Buffer.from(content, 'utf8').toString('base64'), + content: this.toBase64(content), encoding: 'base64' }) }); @@ -239,4 +239,22 @@ export class GitLabService implements GitServiceInterface { .filter(item => item.type === 'blob' && item.path.endsWith('.gitignore')) .map(item => item.path); } + + private toBase64(str: string): string { + const bytes = new TextEncoder().encode(str); + let binary = ''; + bytes.forEach((byte) => { + binary += String.fromCharCode(byte); + }); + return btoa(binary); + } + + private fromBase64(base64: string): string { + const binary = atob(base64.replace(/\s/g, '')); + const bytes = new Uint8Array(binary.length); + for (let i = 0; i < binary.length; i++) { + bytes[i] = binary.charCodeAt(i); + } + return new TextDecoder().decode(bytes); + } }