Deploy deepseek 2
This commit is contained in:
@@ -66,6 +66,9 @@ function resolveWorldAssets(fields, campaign) {
|
||||
if (Array.isArray(fields.inventory)) {
|
||||
for (const entry of fields.inventory) entry.icon = worldAssetUrl(entry.icon, worldUrl);
|
||||
}
|
||||
if (Array.isArray(fields.features)) {
|
||||
for (const entry of fields.features) entry.icon = worldAssetUrl(entry.icon, worldUrl);
|
||||
}
|
||||
}
|
||||
|
||||
async function saveFoundryActor(campaign, source, fullSync = false, replace = false) {
|
||||
@@ -580,24 +583,89 @@ router.post('/sync/map-item', async (req, res) => {
|
||||
});
|
||||
|
||||
// --- Note pages ------------------------------------------------------------
|
||||
// The campaign's notes are read where their authors' table sits: every note
|
||||
// stands as a page of the one journal the world calls "Dragonroll". Notes are
|
||||
// written in Dragonroll, so this copy runs one way — the module reads the notes
|
||||
// and rewrites their pages; nothing of the journal travels back. Its pages keep
|
||||
// the note's id in a `dragonroll-foundry.noteId` flag, and the note keeps the
|
||||
// page's id here, so either side recognises the pairing again after a restart.
|
||||
// The campaign's notes are read where their authors' table sits: each note
|
||||
// stands as a page of the journal of the folder it lives in, and root notes share
|
||||
// the journal the world calls "Dragonroll". Notes are written in Dragonroll, so
|
||||
// this copy runs one way — the module reads the notes and rewrites their pages;
|
||||
// nothing of the journal travels back. Its pages keep the note's id in a
|
||||
// `dragonroll-foundry.noteId` flag, and the note keeps the page's id here, so
|
||||
// either side recognises the pairing again after a restart.
|
||||
|
||||
const NOTE_FOLDER_SEPARATOR = ' / ';
|
||||
|
||||
// The path of the folder a note lives in, from the root down: the module names a
|
||||
// journal after it, so a note in "Sessions / Arc 1" is written into that journal.
|
||||
// A broken parent chain stops at the first folder seen twice instead of looping.
|
||||
function noteFolderPath(folderId, foldersById) {
|
||||
const names = [];
|
||||
const seen = new Set();
|
||||
let folder = folderId ? foldersById.get(String(folderId)) : null;
|
||||
while (folder && !seen.has(String(folder._id))) {
|
||||
seen.add(String(folder._id));
|
||||
if (folder.name) names.unshift(String(folder.name));
|
||||
folder = folder.parentFolder ? foldersById.get(String(folder.parentFolder)) : null;
|
||||
}
|
||||
return names.join(NOTE_FOLDER_SEPARATOR);
|
||||
}
|
||||
|
||||
// The note folders of a campaign, keyed by id, for the path of each note.
|
||||
async function campaignNoteFolders(campaignId) {
|
||||
const folders = await Folder.find({ campaign: campaignId })
|
||||
.select('_id name parentFolder')
|
||||
.lean();
|
||||
return new Map(folders.map((folder) => [String(folder._id), folder]));
|
||||
}
|
||||
|
||||
// A cheap summary of the campaign's notes for the module's change check: the same
|
||||
// notes `/sync/notes` would send, folded into one hash, so a world can tell whether
|
||||
// anything changed without pulling every note's markdown over on every poll. The
|
||||
// folder path travels in the hash too: renaming or moving a folder moves a note to
|
||||
// another journal. The page a note is already mapped to is left out — mapping is
|
||||
// not an edit.
|
||||
router.get('/sync/notes/revision', async (req, res) => {
|
||||
try {
|
||||
const campaign = await syncCampaign(req, res);
|
||||
if (!campaign) return;
|
||||
const notes = await Note.find({ campaign: campaign._id })
|
||||
.select('_id title content folder')
|
||||
.sort({ _id: 1 })
|
||||
.lean();
|
||||
const foldersById = await campaignNoteFolders(campaign._id);
|
||||
const revision = crypto.createHash('sha256')
|
||||
.update(notes.map((note) => [
|
||||
note._id,
|
||||
note.title ?? '',
|
||||
note.content ?? '',
|
||||
note.folder ?? '',
|
||||
noteFolderPath(note.folder, foldersById),
|
||||
].join('\u0000')).join('\u0001'))
|
||||
.digest('hex');
|
||||
res.json({ status: 'ok', revision });
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.json({ status: 'error', msg: 'errors.internal' });
|
||||
}
|
||||
});
|
||||
|
||||
// Every note of the campaign, content included: enough for the module to write
|
||||
// each one as a page. Folders of the notes do not travel — the journal is flat.
|
||||
// each one as a page. A note also carries the path of its folder, which names the
|
||||
// journal the page belongs to; root notes carry an empty path.
|
||||
router.get('/sync/notes', async (req, res) => {
|
||||
try {
|
||||
const campaign = await syncCampaign(req, res);
|
||||
if (!campaign) return;
|
||||
const notes = await Note.find({ campaign: campaign._id })
|
||||
.select('_id title content foundryPageId date')
|
||||
.select('_id title content foundryPageId date folder')
|
||||
.sort({ date: -1 })
|
||||
.lean();
|
||||
res.json({ status: 'ok', notes });
|
||||
const foldersById = await campaignNoteFolders(campaign._id);
|
||||
res.json({
|
||||
status: 'ok',
|
||||
notes: notes.map((note) => ({
|
||||
...note,
|
||||
folderPath: noteFolderPath(note.folder, foldersById),
|
||||
})),
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.json({ status: 'error', msg: 'errors.internal' });
|
||||
|
||||
Reference in New Issue
Block a user