allow update for uploaded routes and implement creator id for routes
This commit is contained in:
@@ -19,6 +19,31 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
return target;
|
||||
}
|
||||
|
||||
// Separate from app/route storage: ordinary cleanup must preserve this identity.
|
||||
const CREATOR_KEY = 'wegwichtel.creator-id.v1';
|
||||
|
||||
function creatorId() {
|
||||
const target = storage();
|
||||
const existing = target.getItem(CREATOR_KEY);
|
||||
if (existing) {
|
||||
if (!/^[a-f0-9]{64}$/.test(existing)) throw new Error(ns.I18n.t("local.error.identity"));
|
||||
return existing;
|
||||
}
|
||||
if (typeof globalThis.crypto?.getRandomValues !== 'function') {
|
||||
throw new Error(ns.I18n.t("local.error.identity"));
|
||||
}
|
||||
const bytes = globalThis.crypto.getRandomValues(new Uint8Array(32));
|
||||
const value = Array.from(bytes, byte => byte.toString(16).padStart(2, '0')).join('');
|
||||
target.setItem(CREATOR_KEY, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
function forgetCreatorId() {
|
||||
if (globalThis.confirm?.(ns.I18n.t("local.confirm-forget-identity")) !== true) return false;
|
||||
storage().removeItem(CREATOR_KEY);
|
||||
return true;
|
||||
}
|
||||
|
||||
function routeKey(id, suffix) {
|
||||
return `${STORAGE_PREFIX}.${encodeURIComponent(String(id))}.${suffix}`;
|
||||
}
|
||||
@@ -499,6 +524,7 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
const inputRoute = routePackage.route || {};
|
||||
const route = {
|
||||
id,
|
||||
creator_id: inputRoute.creator_id || creatorId(),
|
||||
name: String(inputRoute.name || ''),
|
||||
description: String(inputRoute.description || ''),
|
||||
createdAt: inputRoute.createdAt || now,
|
||||
@@ -724,6 +750,8 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
|
||||
ns.LocalRoutes = Object.freeze({
|
||||
STORAGE_PREFIX,
|
||||
creatorId,
|
||||
forgetCreatorId,
|
||||
appendTrackPoint,
|
||||
recordedPositions,
|
||||
replaceRecordedPositions,
|
||||
|
||||
Reference in New Issue
Block a user