Files
homepage-Mirror/src/pages/api/hash.js
TheRolf b39c79bea1 Custom JS and CSS (#1950)
* First commit for custom styles and JS

* Adjusted classes

* Added ids and classes for services and bookmarks

* Apply suggestions from code review

* Remove mime dependency

* Update settings.json

* Detect custom css / js changes, no refresh

* Added preload to custom scripts and styles so they can load earlier

* Added data attribute name for bookmarks too

* Update [path].js

* code style, revert some pointer changes

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
2023-09-10 14:36:54 -07:00

31 lines
948 B
JavaScript

import { join } from "path";
import { createHash } from "crypto";
import { readFileSync } from "fs";
import checkAndCopyConfig, { CONF_DIR } from "utils/config/config";
const configs = ["docker.yaml", "settings.yaml", "services.yaml", "bookmarks.yaml", "widgets.yaml", "custom.css", "custom.js"];
function hash(buffer) {
const hashSum = createHash("sha256");
hashSum.update(buffer);
return hashSum.digest("hex");
}
export default async function handler(req, res) {
const hashes = configs.map((config) => {
checkAndCopyConfig(config);
const configYaml = join(CONF_DIR, config);
return hash(readFileSync(configYaml, "utf8"));
});
// set to date by docker entrypoint, will force revalidation between restarts/recreates
const buildTime = process.env.HOMEPAGE_BUILDTIME?.length ? process.env.HOMEPAGE_BUILDTIME : '';
const combinedHash = hash(hashes.join("") + buildTime);
res.send({
hash: combinedHash,
});
}