Download src/shared/authoring-access.mjs from xlt99/EmboDi: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/xlt99/EmboDi/resolve/main/src/shared/authoring-access.mjs
- Command line
-
hf download hf://spaces/xlt99/EmboDi/src/shared/authoring-access.mjs
-
curl -L -o authoring-access.mjs https://huggingface.co/spaces/xlt99/EmboDi/resolve/main/src/shared/authoring-access.mjs
1.03 kB
| function createAuthoringAccess(makeId) { | |
| const sessions = /* @__PURE__ */ new Map(); | |
| function check(input, write = false) { | |
| const ref = input?.authoringSession; | |
| if (!ref) return null; | |
| const session = sessions.get(ref.id); | |
| if (!session || session.epoch !== ref.epoch) throw Error("Operation expired. Please retry."); | |
| if (write && session.mode !== "edit") throw Error("Enter Edit mode to change the scene"); | |
| return session; | |
| } | |
| return { check, transition(input) { | |
| if (!["edit", "explore"].includes(input.mode)) throw Error("Invalid mode"); | |
| let session = input.id ? sessions.get(input.id) : null; | |
| if (input.id && (!session || session.epoch !== input.epoch)) throw Error("Mode changed. Please refresh."); | |
| session = { id: session?.id || makeId(), mode: input.mode, epoch: (session?.epoch || 0) + 1 }; | |
| sessions.set(session.id, session); | |
| if (sessions.size > 100) sessions.delete(sessions.keys().next().value); | |
| return { ...session }; | |
| } }; | |
| } | |
| export { | |
| createAuthoringAccess | |
| }; | |