mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
fix base64 build issue (#4581)
* fix base64 build issue * remove leading whitespace * fix import * add explanation --------- Co-authored-by: Luke Taylor <service@lukebtaylor.com>
This commit is contained in:
parent
0c378da0d2
commit
7563205c24
4 changed files with 45 additions and 20 deletions
|
|
@ -1,4 +1,4 @@
|
|||
FROM node:22.12 as builder
|
||||
FROM node:22.12 as builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
/**
|
||||
* Utility functions for handling base64 encoding/decoding
|
||||
*/
|
||||
|
||||
/**
|
||||
* Decodes a base64 string to UTF-8 text
|
||||
* Uses Node.js Buffer but with type safety
|
||||
*/
|
||||
export function decodeBase64(base64String: string): string {
|
||||
try {
|
||||
// Use a type-safe approach without relying on global
|
||||
// @ts-ignore - Ignore TypeScript error for Buffer
|
||||
return Buffer.from(base64String, 'base64').toString('utf-8');
|
||||
} catch (error) {
|
||||
console.error('Error decoding base64 string:', error);
|
||||
return base64String; // Return original string if decoding fails
|
||||
}
|
||||
}
|
||||
|
||||
21
packages/local-mail-watcher/src/lib/base64.ts
Normal file
21
packages/local-mail-watcher/src/lib/base64.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* Utility functions for handling base64 encoding/decoding
|
||||
*/
|
||||
|
||||
// Node.js Buffer is globally available
|
||||
// Only import type information - no runtime import
|
||||
// This will be removed during compilation
|
||||
import type {} from '../types/node-buffer';
|
||||
|
||||
/**
|
||||
* Decodes a base64 string to UTF-8 text
|
||||
* Uses Node.js Buffer with type safety
|
||||
*/
|
||||
export function decodeBase64(base64String: string): string {
|
||||
try {
|
||||
return Buffer.from(base64String, 'base64').toString('utf-8');
|
||||
} catch (error) {
|
||||
console.error('Error decoding base64 string:', error);
|
||||
return base64String; // Return original string if decoding fails
|
||||
}
|
||||
}
|
||||
23
packages/local-mail-watcher/src/lib/node-buffer.d.ts
vendored
Normal file
23
packages/local-mail-watcher/src/lib/node-buffer.d.ts
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
declare global {
|
||||
interface Buffer extends Uint8Array {
|
||||
write(string: string, encoding?: BufferEncoding): number;
|
||||
toString(encoding?: BufferEncoding, start?: number, end?: number): string;
|
||||
}
|
||||
|
||||
interface BufferConstructor {
|
||||
from(arrayBuffer: WithImplicitCoercion<ArrayBuffer | SharedArrayBuffer>, byteOffset?: number, length?: number): Buffer;
|
||||
from(data: WithImplicitCoercion<Uint8Array | readonly number[]>): Buffer;
|
||||
from(str: WithImplicitCoercion<string>, encoding?: BufferEncoding): Buffer;
|
||||
alloc(size: number): Buffer;
|
||||
alloc(size: number, fill: string | Buffer | number): Buffer;
|
||||
}
|
||||
|
||||
type WithImplicitCoercion<T> = T | { valueOf(): T };
|
||||
|
||||
type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'latin1' | 'binary' | 'hex';
|
||||
|
||||
const Buffer: BufferConstructor;
|
||||
}
|
||||
|
||||
// This empty export makes TypeScript treat this file as a module
|
||||
export {};
|
||||
Loading…
Reference in a new issue