Skip to content

Commit f8da19d

Browse files
committed
fix(game/server): base64 uploads
1 parent c728aa8 commit f8da19d

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

game/nui/src/capture.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export class Capture {
7979
if (imageData instanceof Blob) {
8080
const formData = new FormData();
8181
formData.append(request.formField ?? 'file', imageData);
82+
8283
return formData;
8384
}
8485

game/server/export.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ global.exports(
4646
remoteConfig: null,
4747
dataType,
4848
});
49-
emitNet('screencapture:captureScreen', source, token, options, dataType);
49+
50+
const opts = {
51+
...options,
52+
encoding: options.encoding ?? 'webp',
53+
}
54+
55+
emitNet('screencapture:captureScreen', source, token, opts, dataType);
5056
},
5157
);

game/server/router.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { CaptureOptions, DataType, RequestBody, StreamUploadData, UploadData } f
33
import FormData from 'form-data';
44
import fetch from 'node-fetch';
55
import { parseFormData } from './form-data';
6+
import { Blob } from 'node:buffer';
67

78
type CfxRequest = {
89
address: string;
@@ -223,14 +224,14 @@ export class Router {
223224
}
224225

225226
async blobToBase64(blob: Blob): Promise<string> {
226-
return new Promise((resolve, reject) => {
227-
const reader = new FileReader();
228-
reader.onerror = reject;
229-
reader.onload = () => {
230-
resolve(reader.result as string);
231-
};
232-
233-
reader.readAsDataURL(blob);
227+
return new Promise(async (resolve, reject) => {
228+
try {
229+
const arrayBuffer = await blob.arrayBuffer();
230+
const base64 = Buffer.from(arrayBuffer).toString('base64');
231+
resolve(base64);
232+
} catch (err) {
233+
reject(err);
234+
}
234235
});
235236
}
236237
}

0 commit comments

Comments
 (0)