/
githubmirror
/
photoprism
Обзор
Документация
Войти
/
githubmirror
/
photoprism
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
frontend/src/model/marker.js
136 строк
3 KB
Michael Mayer
People: Seed type-ahead cache on name save to fix stale suggestions #5666
16 июн 2026, 05:57
16 июн 2026, 05:57
2f94755
Код
Авторство
О чём код?
import RestModel from "model/rest"; import $api from "common/api"; import { DateTime } from "luxon"; import { $config } from "app/session"; import { $gettext } from "common/gettext"; import * as src from "common/src"; import typeaheadCache from "common/typeahead-cache"; export let BatchSize = 60; // Marker represents detected regions (faces or objects) within photos. export class Marker extends RestModel { getDefaults() { return { UID: "", FileUID: "", Thumb: "", Type: "", Src: src.Manual, Name: "", Invalid: false, Review: false, X: 0.0, Y: 0.0, W: 0.0, H: 0.0, CropID: "", FaceID: "", SubjSrc: "", SubjUID: "", Score: 0, Size: 0, }; } route(view) { return { name: view, query: { q: "marker:" + this.getId() } }; } classes(selected) { let classes = ["is-marker", "uid-" + this.getId()]; if (this.Invalid) { classes.push("is-invalid"); } if (this.Review) { classes.push("is-review"); } if (selected) { classes.push("is-selected"); } return classes; } getEntityName() { return this.Name; } getTitle() { return this.Name; } thumbnailUrl(size) { if (!size) { size = "tile_160"; } if (this.Thumb) { return `${$config.contentUri}/t/${this.Thumb}/${$config.previewToken}/${size}`; } else { return `${$config.contentUri}/svg/portrait`; } } getDateString() { return DateTime.fromISO(this.CreatedAt).toLocaleString(DateTime.DATETIME_MED); } approve() { this.Review = false; this.Invalid = false; return this.update(); } reject() { this.Review = false; this.Invalid = true; return this.update(); } setName() { if (!this.Name || this.Name.trim() === "") { // Can't save an empty name. return Promise.resolve(this); } this.SubjSrc = src.Manual; const payload = { SubjSrc: this.SubjSrc, Name: this.Name }; return $api.put(this.getEntityResource(), payload).then((resp) => { this.setValues(resp.data); // Seed the shared people typeahead cache so the saved name is suggestible // immediately, before the subjects WS event (which can lag a quick re-entry // into the next face's name field). typeaheadCache.upsertPerson({ UID: this.SubjUID, Name: this.Name }); return Promise.resolve(this); }); } clearSubject() { return $api.delete(this.getEntityResource(this.getId()) + "/subject").then((r) => Promise.resolve(this.setValues(r.data))); } static batchSize() { return BatchSize; } static setBatchSize(count) { const s = parseInt(count); if (!isNaN(s) && s >= 24) { BatchSize = s; } } static getCollectionResource() { return "markers"; } static getModelName() { return $gettext("Marker"); } } export default Marker;