Removed remnants of EEPROMv2 attempt.

This commit is contained in:
flash 2025-04-11 21:28:27 +00:00
parent b92e6fcd1c
commit 9ba034cf42
Signed by: flash
GPG key ID: 2C9C2C574D47FE3E
2 changed files with 1 additions and 169 deletions
src/mami.js

View file

@ -1,163 +0,0 @@
#include concurrent.js
#include hash.js
const MamiEEPROMv2 = function(baseUrl, getAuthLine, poolName) {
if(typeof baseUrl !== 'string')
throw 'baseUrl must be a string';
if(typeof getAuthLine !== 'function')
throw 'getAuthLine must be a function';
if(typeof poolName !== 'string')
throw 'poolName must be a string';
const CHUNK_SIZE = 4 * 1024 * 1024;
return {
create: fileInput => {
if(!(fileInput instanceof File))
throw 'fileInput must be an instance of window.File';
let userAborted = false;
let abortHandler;
let progressHandler;
const reportProgress = ev => {
if(progressHandler !== undefined)
progressHandler({
loaded: ev.loaded,
total: ev.total,
progress: ev.total <= 0 ? 0 : ev.loaded / ev.total,
});
};
const createTask = async (buffer, name, type, size) => {
const params = new URLSearchParams;
params.append('size', size);
params.append('type', type);
params.append('name', name);
params.append('hash', await MamiHash(buffer));
const { status, body } = await $xhr.post(`${baseUrl}/v1/storage/pools/${poolName}/uploads`, {
type: 'json',
headers: {
Authorization: getAuthLine(),
},
abort: handler => abortHandler = handler,
}, params);
if(body === null)
throw "Could not create upload task for some reason.";
if(status !== 200 && status !== 201)
throw body.english ?? body.error ?? `Upload failed with status code ${status}`;
return body;
};
const putChunk = async (taskInfo, buffer, index, size) => {
const offset = size * index;
buffer = buffer.subarray(offset, Math.min(buffer.length, offset + size));
const { status, body } = await $xhr.put(taskInfo.task_url, {
type: 'json',
headers: {
'X-Content-Index': index,
},
}, buffer);
if(status === 202)
return;
if(body === null)
throw `Upload of chunk #${offset} failed with status code ${status}`;
throw body.english ?? body.error ?? `Upload of chunk #${offset} failed with status code ${status}`;
};
const finishTask = async (taskInfo) => {
const { status, body } = await $xhr.post(`${baseUrl}/v1/storage/tasks/${taskInfo.task_id}`, { type: 'json' });
if(body === null)
throw "Could not complete upload task for some reason.";
if(status !== 201)
throw body.english ?? body.error ?? `Upload failed with status code ${status}`;
return body;
};
return {
abort: () => {
userAborted = true;
if(typeof abortHandler === 'function')
abortHandler();
},
onProgress: handler => {
if(typeof handler !== 'function')
throw 'handler must be a function';
progressHandler = handler;
},
start: async progress => {
if(userAborted)
throw 'File upload was cancelled by the user, it cannot be restarted.';
try {
const buffer = new Uint8Array(await fileInput.arrayBuffer());
let upload;
const task = await createTask(buffer, fileInput.name, fileInput.type, fileInput.size);
if(task.state === 'complete') {
upload = task.upload;
} else if(task.state === 'pending') {
const chunks = Math.ceil(buffer.length / CHUNK_SIZE);
await MamiRunConcurrent((() => {
const promises = [];
for(let i = 0; i < chunks; ++i)
promises.push(async () => await putChunk(task, buffer, i, CHUNK_SIZE));
return promises;
})());
const result = await finishTask(task);
if(result.state !== 'complete')
throw `Upload task finished with unsupported state: ${result.state}`;
upload = result.upload;
} else
throw `Upload task is in unsupported state: ${task.state}`;
upload.thumb = `${upload.url}.t`;
upload.isImage = () => upload.type.startsWith('image/');
upload.isVideo = () => upload.type.startsWith('video/');
upload.isAudio = () => upload.type.startsWith('audio/');
upload.isMedia = () => upload.isImage() || upload.isAudio() || upload.isVideo();
return Object.freeze(upload);
} catch(ex) {
if(userAborted)
throw '';
console.error(ex);
throw ex;
}
},
};
},
delete: async fileInfo => {
if(typeof fileInfo !== 'object')
throw 'fileInfo must be an object';
if(typeof fileInfo.id !== 'string')
throw 'fileInfo.id must be a string';
const { status, body } = await $xhr.delete(`${baseUrl}/v1/storage/uploads/${fileInfo.id}`, {
type: 'json',
headers: {
Authorization: getAuthLine(),
},
});
if(status === 204)
return;
if(body === null)
throw `Delete failed with status code ${status}`;
throw body.english ?? body.error ?? `Delete failed with status code ${status}`;
},
};
};

View file

@ -28,7 +28,6 @@ window.Umi = { UI: {} };
#include controls/ping.jsx
#include controls/views.js
#include eeprom/eeprom.js
#include eeprom/eepromv2.js
#include emotes/picker.jsx
#include notices/baka.jsx
#include notices/youare.jsx
@ -150,7 +149,6 @@ const MamiInit = async args => {
settings.define('keepEmotePickerOpen').default(true).create();
settings.define('doNotMarkLinksAsVisited').default(false).create();
settings.define('showMarkupSelector').type(['always', 'focus', 'never']).default('always').create();
settings.define('dbgEEPROMv2').default(false).create();
const noNotifSupport = !('Notification' in window);
settings.define('enableNotifications').default(false).immutable(noNotifSupport).critical().create();
@ -629,7 +627,6 @@ const MamiInit = async args => {
category.warning("Only touch these settings if you're ABSOLUTELY sure you know what you're doing, you're on your own if you break something.");
category.setting('dumpPackets').title('Dump packets to console').done();
category.setting('dumpEvents').title('Dump events to console').done();
category.setting('dbgEEPROMv2').title('Use EEPROM v2 API (requires reload)').done();
category.setting('marqueeAllNames').title('Apply marquee on everyone (requires reload)').done();
category.setting('dbgAnimDurationMulti').title('Animation multiplier').type('range').done();
category.button('Test kick/ban notice', async button => {
@ -707,9 +704,7 @@ const MamiInit = async args => {
});
ctx.eeprom = settings.get('dbgEEPROMv2')
? new MamiEEPROMv2(futami.get('api'), MamiMisuzuAuth.getLine, 'chat')
: new MamiEEPROM(futami.get('eeprom2'), MamiMisuzuAuth.getLine);
ctx.eeprom = new MamiEEPROM(futami.get('eeprom2'), MamiMisuzuAuth.getLine);
sbUploads.addOption({
name: 'view',