feat(media hosting): add imgbb provider

This commit is contained in:
Tommaso Casaburi
2026-05-01 22:52:54 +07:00
parent e2154b3edf
commit 78e5d58d08
10 changed files with 136 additions and 12 deletions
+27
View File
@@ -155,6 +155,28 @@ describe('media-upload-automation', () => {
expect(fakeWindow.destroy).toHaveBeenCalledOnce();
});
it('uploads to ImgBB through the hidden BrowserWindow recipe', async () => {
const recipe = MEDIA_UPLOAD_RECIPES.imgbb;
const fakeWindow = createFakeBrowserWindow({
getNodeId: (selector) => {
if (selector === recipe.fileInputSelectorCandidates[0]) return 10;
if (selector === recipe.submitSelectorCandidates[0]) return 20;
return 0;
},
runtimeValues: [true, 'https://i.ibb.co/example/uploaded.png'],
});
electronState.createWindow = () => fakeWindow;
const result = await automateUploadMedia({ provider: 'imgbb', filePath: '/tmp/upload.png' });
expect(result).toEqual({ url: 'https://i.ibb.co/example/uploaded.png', provider: 'imgbb' });
expect(fakeWindow.loadURL).toHaveBeenCalledWith(recipe.uploadUrl);
expect(fakeWindow.webContents.debugger.sendCommand).toHaveBeenCalledWith('DOM.setFileInputFiles', {
nodeId: 10,
files: ['/tmp/upload.png'],
});
});
it('fails fast when a blocked indicator is present before upload begins', async () => {
const recipe = MEDIA_UPLOAD_RECIPES.imgur;
const fakeWindow = createFakeBrowserWindow({
@@ -242,4 +264,9 @@ describe('media-upload-automation + recipes integration', () => {
expect(recipe.successExtractor.selectorCandidates.length).toBeGreaterThanOrEqual(1);
}
});
it('imgbb success extractor targets direct-media domain', () => {
const imgbbSelectors = MEDIA_UPLOAD_RECIPES.imgbb.successExtractor.selectorCandidates;
expect(imgbbSelectors.some((selector) => selector.includes('i.ibb.co') || selector.includes('html-embed-medium'))).toBe(true);
});
});