feat: initial scaffold - backend, frontend, Prisma schema, Docker
- Prisma schema: User, Session, RepoConfig, Preview, Job, WebhookToken, NoConfigComment, AdminSettings - Backend: auth (login/logout/me/first-user setup), webhook handler with HMAC verification, EC2 service, SSH service, deploy pipeline, job queue worker, cron workers - Frontend: Login with first-user detection, Dashboard, PreviewDetail with live log streaming, Settings, Repos config, Admin panel, SetupWizard, Privacy page - Docker Compose and Dockerfile for self-hosted deployment - Uses bcryptjs for Node 24 compatibility Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Vendored
+100
@@ -0,0 +1,100 @@
|
||||
"use strict";
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var cronWorker_exports = {};
|
||||
__export(cronWorker_exports, {
|
||||
startCronWorkers: () => startCronWorkers
|
||||
});
|
||||
module.exports = __toCommonJS(cronWorker_exports);
|
||||
var import_node_cron = __toESM(require("node-cron"));
|
||||
var import_db = require("../lib/db");
|
||||
var import_logger = require("../lib/logger");
|
||||
var import_adminSettings = require("../lib/adminSettings");
|
||||
const log = (0, import_logger.createLogger)("CRON");
|
||||
function startCronWorkers() {
|
||||
import_node_cron.default.schedule("*/30 * * * *", async () => {
|
||||
try {
|
||||
await checkInactivity();
|
||||
} catch (e) {
|
||||
log.error({ e }, "Inactivity check error");
|
||||
}
|
||||
});
|
||||
import_node_cron.default.schedule("0 3 * * *", async () => {
|
||||
try {
|
||||
await dailyCleanup();
|
||||
} catch (e) {
|
||||
log.error({ e }, "Daily cleanup error");
|
||||
}
|
||||
});
|
||||
log.info("Cron workers started");
|
||||
}
|
||||
async function checkInactivity() {
|
||||
const settings = await (0, import_adminSettings.getAdminSettings)();
|
||||
const now = /* @__PURE__ */ new Date();
|
||||
const running = await import_db.prisma.preview.findMany({
|
||||
where: { status: "RUNNING" }
|
||||
});
|
||||
for (const preview of running) {
|
||||
const inactivityMs = settings.maxConcurrentInstancesPerUser;
|
||||
const repoConfig = await import_db.prisma.repoConfig.findUnique({ where: { id: preview.repoConfigId } });
|
||||
if (!repoConfig) continue;
|
||||
const deadline = new Date(preview.lastActivityAt.getTime() + repoConfig.inactivityHours * 3600 * 1e3);
|
||||
if (now >= deadline) {
|
||||
log.info({ previewId: preview.id }, "Preview inactive, enqueuing INACTIVITY_STOP");
|
||||
await import_db.prisma.job.create({
|
||||
data: {
|
||||
previewId: preview.id,
|
||||
type: "INACTIVITY_STOP",
|
||||
status: "PENDING",
|
||||
payload: {}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
async function dailyCleanup() {
|
||||
const settings = await (0, import_adminSettings.getAdminSettings)();
|
||||
const cutoff = new Date(Date.now() - settings.previewRetentionDays * 86400 * 1e3);
|
||||
const old = await import_db.prisma.preview.findMany({
|
||||
where: {
|
||||
status: { in: ["STOPPED", "FAILED"] },
|
||||
stoppedAt: { lt: cutoff }
|
||||
},
|
||||
select: { id: true }
|
||||
});
|
||||
for (const { id } of old) {
|
||||
await import_db.prisma.job.deleteMany({ where: { previewId: id } });
|
||||
await import_db.prisma.preview.delete({ where: { id } });
|
||||
}
|
||||
if (old.length > 0) log.info({ count: old.length }, "Cleaned up old previews");
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
startCronWorkers
|
||||
});
|
||||
//# sourceMappingURL=cronWorker.js.map
|
||||
Reference in New Issue
Block a user