Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Image history entries can be deleted from the library

Bowen Xuef9b987cad4a2
diff --git a/freevideo_engine/image_gen/service.py b/freevideo_engine/image_gen/service.py
index 1b4d5cd..a7b9e68 100644
--- a/freevideo_engine/image_gen/service.py
+++ b/freevideo_engine/image_gen/service.py
@@ -288,16 +288,43 @@ class Service:
names = sorted(named, reverse=True) + [name for _, name in sorted(older, reverse=True)]
return dict(items=[dict(file='freevideo-image/' + name, name=name) for name in names[:HISTORY_LIMIT]])
- def history_delete(self, name):
+ def history_path(self, name):
+ """The picture a history name stands for; ValueError when it is none of ours, missing when it is already gone."""
leaf = name.rpartition('/')[2] if isinstance(name, str) else ''
if not (HISTORY_NAME.fullmatch(leaf) or LEGACY_NAME.fullmatch(leaf)) or name != 'freevideo-image/' + leaf:
raise ValueError('invalid_media')
path = self.output_directory() / leaf
- if path.is_symlink() or not path.is_file() or (LEGACY_NAME.fullmatch(leaf) and not self.legacy_picture(path)):
+ if path.is_symlink() or (path.exists() and not path.is_file()) or (
+ LEGACY_NAME.fullmatch(leaf) and path.is_file() and not self.legacy_picture(path)):
+ raise ValueError('invalid_media')
+ return path
+
+ def history_delete(self, name):
+ path = self.history_path(name)
+ if not path.is_file():
raise ValueError('invalid_media')
path.unlink()
return self.history()
+ def history_delete_many(self, names):
+ """Delete each picture on its own; the ones that stay are listed with why (busy, missing, invalid)."""
+ if not isinstance(names, list) or len(names) > HISTORY_LIMIT:
+ raise ValueError('invalid_request')
+ failed = []
+ for name in dict.fromkeys(names):
+ try:
+ path = self.history_path(name)
+ except ValueError:
+ failed.append(dict(file=name if isinstance(name, str) else '', reason='invalid'))
+ continue
+ try:
+ path.unlink()
+ except FileNotFoundError:
+ failed.append(dict(file=name, reason='missing'))
+ except OSError:
+ failed.append(dict(file=name, reason='busy'))
+ return dict(self.history(), failed=failed)
+
def history_open(self):
"""Show the folder in the file manager of this machine."""
folder = str(self.output_directory())
@@ -1199,6 +1226,8 @@ def register():
result = service.history()
elif name == 'history-delete':
result = service.history_delete(value.get('file'))
+ elif name == 'history-delete-many':
+ result = service.history_delete_many(value.get('files'))
elif name == 'history-open':
if request.remote not in ('127.0.0.1', '::1'):
raise ValueError('invalid_request')
diff --git a/web/image_editor.css b/web/image_editor.css
index a9369f1..e9b0e64 100644
--- a/web/image_editor.css
+++ b/web/image_editor.css
@@ -94,6 +94,16 @@ button.fv-ie-size:hover{background:var(--fv-hover);color:var(--fv-ink)}
.fv-ie-gen-history-use{position:absolute;top:4px;left:4px;width:20px;height:20px;padding:0;border:0;border-radius:10px;background:rgba(0,0,0,.7);color:#fff;font-size:16px;line-height:18px;opacity:0;cursor:pointer}
.fv-ie-gen-history-tile:hover>.fv-ie-gen-history-use,.fv-ie-gen-history-tile:hover>.fv-ie-gen-history-delete,.fv-ie-gen-history-use:focus-visible,.fv-ie-gen-history-delete:focus-visible{opacity:1}
.fv-ie-gen-history-delete{opacity:0;top:4px;right:4px;width:20px;height:20px;border-radius:10px;font-size:16px;line-height:18px;background:rgba(0,0,0,.7);color:#fff}
+.fv-ie-gen-history-foot{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:4px;margin-top:6px}
+.fv-ie-gen-history-foot-end{display:flex;gap:4px}
+.fv-ie-gen-history-foot .fv-ie-button{min-height:32px;padding:5px 9px}
+.fv-ie-gen-history-delete-all{min-width:88px}
+.fv-ie-gen-history-foot .fv-ie-gen-history-confirm{background:var(--fv-danger);border-color:var(--fv-danger);color:#fff}
+.fv-ie-gen-history-idle{opacity:.5;pointer-events:none}
+.fv-ie-gen-history-ticked img{outline:2px solid var(--fv-accent,#3b82f6);outline-offset:-2px}
+.fv-ie-gen-history-tick{position:absolute;top:4px;left:4px;width:20px;height:20px;border:2px solid #fff;border-radius:10px;background:rgba(0,0,0,.45);color:#fff;font-size:13px;line-height:16px;text-align:center;pointer-events:none}
+.fv-ie-gen-history-on{background:var(--fv-accent,#3b82f6)}
+.fv-ie-gen-history-why{position:absolute;left:0;right:0;bottom:0;padding:2px 4px;border-radius:0 0 6px 6px;background:rgba(192,57,43,.9);color:#fff;font-size:var(--fv-micro);text-align:center;pointer-events:none}
.fv-image-editor .fv-ie-gen-prompt{position:absolute;inset:0 0 auto;width:100%;height:32px;min-height:32px;max-height:80px;resize:none;padding:3px 9px;border:1px solid var(--fv-border);border-radius:var(--fv-r-sm);background:var(--fv-raised);line-height:24px;overflow-y:auto}
.fv-ie-gen-prompt:disabled{opacity:.5}
.fv-ie-gen-note{align-self:center;min-width:0;overflow-wrap:anywhere;font-variant-numeric:tabular-nums}
diff --git a/web/image_generation.js b/web/image_generation.js
index c2dd08b..894a0eb 100644
--- a/web/image_generation.js
+++ b/web/image_generation.js
@@ -106,6 +106,7 @@ export function createImageGenClient(fetchImpl = globalThis.fetch.bind(globalThi
// Every picture generated on this machine, newest first; the engine keeps them in a folder.
async history() { return (await post('history', {})).items || []; },
async historyDelete(file) { return (await post('history-delete', {file})).items || []; },
+ async historyDeleteMany(files) { const answer = await post('history-delete-many', {files}); return {items: answer.items || [], failed: answer.failed || []}; },
historyOpen: () => post('history-open', {}),
// The prompts and sizes of a new character's five pictures (the Agent's cards use the same ones).
castViews: async description => (await post('cast-views', {description})).views,
@@ -649,42 +650,95 @@ export function createImageGeneration({client, renderer, t, getDoc, getSelection
summary.title = t('History', '历史'); summary.setAttribute('aria-label', summary.title);
const list = el('div', null, 'fv-ie-menu-list');
menu.append(summary, list);
+ // Choosing several: the ticked files, the reason each one that stayed gives, and the two-step confirm of the delete button.
+ let selecting = false, armed = null, failed = false;
+ const chosen = new Set(), stayed = new Map();
+ const reasons = {busy: t('In use', '被占用'), missing: t('Already gone', '已不存在'), invalid: t('Not deleted', '未删除')};
+ const disarm = () => { clearTimeout(armed); armed = null; };
const draw = () => {
list.replaceChildren();
+ if (failed) list.append(el('div', t('Could not delete this image', '无法删除这张图片'), 'fv-ie-menu-label'));
if (!past.length) { list.append(el('div', t('No images generated yet', '还没有生成过图片'), 'fv-ie-menu-label')); return; }
const grid = el('div', null, 'fv-ie-gen-history-grid');
for (const item of past) {
const tile = el('div', null, 'fv-ie-gen-history-tile');
- const place = button('', item.name, () => { menu.open = false; onPlace?.(item.file, item.name); }, 'fv-ie-gen-history-pick');
+ const ticked = chosen.has(item.file);
+ const place = button('', item.name, () => {
+ if (!selecting) { menu.open = false; onPlace?.(item.file, item.name); return; }
+ if (chosen.has(item.file)) chosen.delete(item.file); else chosen.add(item.file);
+ stayed.delete(item.file); disarm(); draw();
+ }, 'fv-ie-gen-history-pick' + (ticked ? ' fv-ie-gen-history-ticked' : ''));
+ if (selecting) place.setAttribute('aria-pressed', String(ticked));
const picture = el('img'); picture.src = resolve(item.file); picture.alt = item.name; picture.loading = 'lazy';
place.append(picture); tile.append(place);
+ if (selecting) {
+ tile.append(el('span', ticked ? '✓' : '', 'fv-ie-gen-history-tick' + (ticked ? ' fv-ie-gen-history-on' : '')));
+ if (stayed.has(item.file)) tile.append(el('span', stayed.get(item.file), 'fv-ie-gen-history-why'));
+ grid.append(tile);
+ continue;
+ }
if (mode === 'edit' && getDoc().layers.length && limit() > 1) {
const use = button('+', t('Use as reference', '用作参考图'), () => {
references = addReference(references, {file: item.file, label: item.name}, limit()); menu.open = false; update();
}, 'fv-ie-gen-history-use');
use.setAttribute('aria-label', use.title); tile.append(use);
}
- let armed = null;
+ let single = null;
const remove = button('×', t('Delete', '删除'), async () => {
- if (!armed) {
+ if (!single) {
remove.textContent = t('Delete', '删除'); remove.classList.add('fv-ie-gen-history-confirm');
- armed = setTimeout(() => { armed = null; remove.textContent = '×'; remove.classList.remove('fv-ie-gen-history-confirm'); }, 3000);
+ single = setTimeout(() => { single = null; remove.textContent = '×'; remove.classList.remove('fv-ie-gen-history-confirm'); }, 3000);
return;
}
- clearTimeout(armed);
- try { past = await client.historyDelete(item.file); } catch { return; }
+ clearTimeout(single);
+ try { past = await client.historyDelete(item.file); failed = false; } catch {
+ // Read the folder again: a picture that is gone just leaves the list, one that is still there is named as kept.
+ failed = true;
+ try { past = await client.history(); failed = past.some(row => row.file === item.file); } catch { /* keep the list shown */ }
+ }
draw();
}, 'fv-ie-gen-ref-remove fv-ie-gen-history-delete');
remove.setAttribute('aria-label', remove.title); tile.append(remove);
grid.append(tile);
}
list.append(grid);
- if (['localhost', '127.0.0.1', '[::1]'].includes(location.hostname))
- list.append(button(t('Open folder', '打开文件夹'), null, () => { void client.historyOpen().catch(() => {}); }, 'fv-ie-menu-item'));
+ const foot = el('div', null, 'fv-ie-gen-history-foot');
+ if (selecting) {
+ const all = button(chosen.size === past.length ? t('Deselect all', '全不选') : t('Select all', '全选'), null, () => {
+ if (chosen.size === past.length) chosen.clear(); else for (const row of past) chosen.add(row.file);
+ stayed.clear(); disarm(); draw();
+ }, 'fv-ie-button');
+ const del = button(armed ? t('Confirm delete', '确认删除') : t('Delete ' + chosen.size, '删除 ' + chosen.size + ' 张'), null, async () => {
+ if (!chosen.size) return;
+ if (!armed) { armed = setTimeout(() => { armed = null; draw(); }, 3000); draw(); return; }
+ disarm();
+ let answer;
+ try { answer = await client.historyDeleteMany([...chosen]); } catch { answer = null; }
+ stayed.clear(); failed = false;
+ if (!answer) {
+ try { past = await client.history(); } catch { /* keep the list shown */ }
+ for (const file of chosen) if (past.some(row => row.file === file)) stayed.set(file, reasons.invalid);
+ } else {
+ past = answer.items;
+ for (const row of answer.failed) if (row.reason !== 'missing') stayed.set(row.file, reasons[row.reason] || reasons.invalid);
+ }
+ for (const file of [...chosen]) if (!stayed.has(file)) chosen.delete(file);
+ draw();
+ }, 'fv-ie-button fv-ie-danger fv-ie-gen-history-delete-all' + (armed ? ' fv-ie-gen-history-confirm' : '') + (chosen.size ? '' : ' fv-ie-gen-history-idle'));
+ const cancel = button(t('Cancel', '取消'), null, () => { selecting = false; chosen.clear(); stayed.clear(); disarm(); draw(); }, 'fv-ie-button');
+ foot.append(all, el('span', null, 'fv-ie-gen-history-foot-end'));
+ foot.lastChild.append(cancel, del);
+ } else {
+ foot.append(button(t('Select', '选择'), null, () => { selecting = true; failed = false; draw(); }, 'fv-ie-menu-item'));
+ if (['localhost', '127.0.0.1', '[::1]'].includes(location.hostname))
+ foot.append(button(t('Open folder', '打开文件夹'), null, () => { void client.historyOpen().catch(() => {}); }, 'fv-ie-menu-item'));
+ }
+ list.append(foot);
};
menu.ontoggle = async () => {
if (!menu.open) return;
try { past = await client.history(); } catch { past = []; }
+ selecting = false; chosen.clear(); stayed.clear(); disarm(); failed = false;
draw();
// Open upward when the list does not fit below, and keep it inside the window.
list.classList.remove('fv-ie-gen-history-up'); list.style.right = '';