SHA256
Обновить хранение вложений R2
This commit is contained in:
@@ -49,12 +49,15 @@ class TestElement {
|
||||
|
||||
function loadRenderer() {
|
||||
const viewerCalls = [];
|
||||
const warningCalls = [];
|
||||
const navigations = [];
|
||||
let approveWarning = true;
|
||||
const normalized = source
|
||||
.replace(/^import .*;\s*$/gm, '')
|
||||
.replace(/^export /gm, '');
|
||||
const factory = new Function('t', 'th', 'formatNumber', 'openMediaViewer', 'buildArweaveDataUrl',
|
||||
'validateArweaveTxId', 'validateSha256Hex', 'resolvePublicFileUrl', 'validatePublicPiecesRoot', 'document', 'window', 'fetch',
|
||||
`${normalized}\nreturn { getAttachmentKind, createAttachmentCarouselElement, parseMessageAttachments };`);
|
||||
'validateArweaveTxId', 'validateSha256Hex', 'resolvePublicFileUrl', 'validatePublicPiecesRoot', 'confirmDialog', 'document', 'window', 'fetch',
|
||||
`${normalized}\nreturn { getAttachmentKind, isPotentiallyActiveAttachment, createAttachmentCarouselElement, parseMessageAttachments };`);
|
||||
const api = factory(
|
||||
(key) => key,
|
||||
() => '<span>FILE</span></div>',
|
||||
@@ -65,11 +68,12 @@ function loadRenderer() {
|
||||
(id) => /^[a-f0-9]{64}$/.test(id),
|
||||
async ({ pr, sha256 }) => pr ? `https://files.shineup.me/${pr}` : `https://old.example/files/${sha256}`,
|
||||
validatePublicPiecesRoot,
|
||||
async (options) => { warningCalls.push(options); return approveWarning; },
|
||||
{ createElement: (tag) => new TestElement(tag) },
|
||||
{ location: { origin: 'https://shineup.me' }, open() {} },
|
||||
{ location: { origin: 'https://shineup.me', assign: (url) => navigations.push(url) }, open() {} },
|
||||
async () => ({ ok: true }),
|
||||
);
|
||||
return { ...api, viewerCalls };
|
||||
return { ...api, viewerCalls, warningCalls, navigations, setApproveWarning: (value) => { approveWarning = value; } };
|
||||
}
|
||||
|
||||
const settle = () => new Promise((resolve) => setImmediate(resolve));
|
||||
@@ -154,3 +158,55 @@ test('просмотрщик импортирует t для aria-label диал
|
||||
const viewer = await readFile(new URL('../js/components/media-viewer.js', import.meta.url), 'utf8');
|
||||
assert.match(viewer, /import \{ t, th \} from '\.\.\/i18n\/index\.js';/);
|
||||
});
|
||||
|
||||
|
||||
test('публичное видео не получает src до входа в область просмотра', async () => {
|
||||
const previous = globalThis.IntersectionObserver;
|
||||
const observers = [];
|
||||
class FakeIntersectionObserver {
|
||||
constructor(callback, options) { this.callback = callback; this.options = options; this.targets = new Set(); observers.push(this); }
|
||||
observe(node) { this.targets.add(node); }
|
||||
unobserve(node) { this.targets.delete(node); }
|
||||
disconnect() { this.targets.clear(); }
|
||||
reveal(node) { this.callback([{ target: node, isIntersecting: true }]); }
|
||||
}
|
||||
globalThis.IntersectionObserver = FakeIntersectionObserver;
|
||||
try {
|
||||
const { createAttachmentCarouselElement } = loadRenderer();
|
||||
const root = createAttachmentCarouselElement([{ name: 'clip.mp4', size: 1000, pr: 'A'.repeat(43), mm: 'video/mp4' }]);
|
||||
await settle();
|
||||
const video = root.querySelectorAll('video')[0];
|
||||
assert.equal(video.preload, 'none');
|
||||
assert.equal(video.src, undefined);
|
||||
assert.equal(observers.length, 1);
|
||||
observers[0].reveal(video);
|
||||
assert.equal(video.src, `https://files.shineup.me/${'A'.repeat(43)}`);
|
||||
assert.equal(video.preload, 'metadata');
|
||||
assert.equal(observers[0].targets.size, 0);
|
||||
} finally {
|
||||
if (previous === undefined) delete globalThis.IntersectionObserver;
|
||||
else globalThis.IntersectionObserver = previous;
|
||||
}
|
||||
});
|
||||
|
||||
test('HTML/SVG открываются только после подтверждения, отказ не навигирует', async () => {
|
||||
const api = loadRenderer();
|
||||
const root = api.createAttachmentCarouselElement([
|
||||
{ name: 'vector.svg', size: 500, pr: 'A'.repeat(43), mm: 'image/svg+xml' },
|
||||
{ name: 'run.html', size: 400, pr: 'A'.repeat(43), mm: 'text/html' },
|
||||
]);
|
||||
await settle();
|
||||
assert.equal(root.querySelectorAll('img').length, 0);
|
||||
assert.equal(root.querySelectorAll('video').length, 0);
|
||||
assert.match(root.children[0].children[0].className, /file-card/);
|
||||
api.setApproveWarning(false);
|
||||
root.children[0].children[0].fire('click');
|
||||
await settle();
|
||||
assert.equal(api.warningCalls.length, 1);
|
||||
assert.equal(api.navigations.length, 0);
|
||||
api.setApproveWarning(true);
|
||||
root.children[1].children[0].fire('click');
|
||||
await settle();
|
||||
assert.equal(api.warningCalls.length, 2);
|
||||
assert.deepEqual(api.navigations, [`https://files.shineup.me/${'A'.repeat(43)}`]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user