Use xml-js over xml2js lib

Add Go button in paste modal (frontend)

Signed-off-by: Joe Ma <rikkaneko23@gmail.com>
This commit is contained in:
Joe Ma 2024-02-05 20:10:39 +08:00
parent d2a1dd13b8
commit 63578bcf9d
No known key found for this signature in database
GPG key ID: 7A0ECF5F5EDC587F
6 changed files with 113 additions and 75 deletions

View file

@ -1,7 +1,7 @@
import { Router } from 'itty-router';
import { sha256 } from 'js-sha256';
import { AwsClient } from 'aws4fetch';
import { parseStringPromise } from 'xml2js';
import { xml2js } from 'xml-js';
import { ERequest, Env, PasteIndexEntry } from '../types';
import { gen_id, get_paste_info_obj } from '../utils';
import { UUID_LENGTH } from '../constant';
@ -217,11 +217,14 @@ router.post('/complete/:uuid', async (request, env, ctx) => {
});
if (objectmeta.ok) {
const xml = await objectmeta.text();
const parsed = await parseStringPromise(xml, {
tagNameProcessors: [(name) => name.toLowerCase()],
const parsed: any = xml2js(xml, {
compact: true,
nativeType: true,
alwaysArray: false,
elementNameFn: (val) => val.toLowerCase(),
});
const file_size = parsed.getobjectattributesresponse.objectsize[0];
if (parseInt(file_size) !== descriptor.size) {
const file_size: number = parsed.getobjectattributesresponse.objectsize._text;
if (file_size !== descriptor.size) {
return new Response('This paste is not finishing the upload.\n', {
status: 400,
});