Get the module foundations and the Artist app created

This commit is contained in:
Oliver 2026-01-17 21:54:41 -07:00
parent 8744b6c562
commit ffa2162fbd
20 changed files with 590 additions and 0 deletions

14
module/utils/dialogs.mjs Normal file
View file

@ -0,0 +1,14 @@
import { filePath } from "../consts.mjs";
const { DialogV2 } = foundry.applications.api;
const { renderTemplate } = foundry.applications.handlebars;
export async function promptViaTemplate(title, template, context = {}) {
const content = await renderTemplate(filePath(template), context);
return DialogV2.input({
window: {
title,
},
content,
});
};

49
module/utils/fs.mjs Normal file
View file

@ -0,0 +1,49 @@
import { __ID__, filePath } from "../consts.mjs";
const { fetchJsonWithTimeout } = foundry.utils;
export async function lastModifiedAt(path) {
try {
const response = await fetch(filePath(path), { method: `HEAD` });
return response.headers.get(`Last-Modified`);
} catch {
return null;
};
};
export async function getFile(path) {
try {
return fetchJsonWithTimeout(filePath(path));
} catch {
return undefined;
};
};
/**
* @param {string} path
* @param {any} data
*/
export async function uploadJson(path, filename, data) {
// uploadPersistent adds "storage" into the path automatically
if (path.startsWith(`storage/`)) {
path = path.slice(8);
};
if (path.endsWith(`/`)) {
path = path.slice(0, -1);
};
const picker = foundry.applications.apps.FilePicker.implementation;
try {
const file = new File(
[JSON.stringify(data)],
filename,
{ type: `text/plain` },
);
await picker.uploadPersistent(
__ID__,
path,
file,
);
} catch {};
};