DevPlace CI / test (push) Failing after 25m18s
- Add `devplace backups` CLI subcommands (list, run, prune, clear) with job enqueueing and orphan cleanup - Introduce `BACKUPS_DIR` and `BACKUP_STAGING_DIR` config paths for backup storage - Implement `schedule_correction` and `schedule_modification` calls in content creation, comment creation, and comment editing flows - Add `DEFAULT_CORRECTION_PROMPT` and `DEFAULT_MODIFIER_PROMPT` config constants for AI content processing - Document timezone-aware date display using `local_dt`/`dt_ago` Jinja globals with client-side `Intl` localization - Update README with AI content correction/modifier support in direct messages via `@ai` inline instructions - Add `track_action(user["uid"], "vote")` call on upvote in `apply_vote`
53 lines
1.8 KiB
JavaScript
53 lines
1.8 KiB
JavaScript
// retoor <retoor@molodetz.nl>
|
|
|
|
import { Http } from "./Http.js";
|
|
|
|
class AiCorrection {
|
|
constructor() {
|
|
this.root = document.querySelector("[data-ai-correction]");
|
|
if (!this.root) return;
|
|
this.username = this.root.dataset.username;
|
|
this.toggle = this.root.querySelector("[data-ai-correction-toggle]");
|
|
this.mode = this.root.querySelector("[data-ai-correction-sync]");
|
|
this.prompt = this.root.querySelector("[data-ai-correction-prompt]");
|
|
this.status = this.root.querySelector("[data-ai-correction-status]");
|
|
this.save = this.root.querySelector("[data-ai-correction-save]");
|
|
if (this.save) this.save.addEventListener("click", () => this.submit());
|
|
}
|
|
|
|
async submit() {
|
|
if (!this.toggle || !this.prompt) return;
|
|
this.save.disabled = true;
|
|
this.setStatus("Saving...", "");
|
|
try {
|
|
await Http.send(`/profile/${this.username}/ai-correction`, {
|
|
enabled: this.toggle.checked ? "true" : "false",
|
|
sync: this.mode && this.mode.value === "sync" ? "true" : "false",
|
|
prompt: this.prompt.value,
|
|
});
|
|
this.setStatus("Saved", "success");
|
|
this.flash("AI correction settings saved", "success");
|
|
} catch (error) {
|
|
this.setStatus("Could not save", "error");
|
|
this.flash("Could not save AI correction settings", "error");
|
|
} finally {
|
|
this.save.disabled = false;
|
|
}
|
|
}
|
|
|
|
setStatus(message, type) {
|
|
if (!this.status) return;
|
|
this.status.textContent = message;
|
|
this.status.dataset.state = type;
|
|
}
|
|
|
|
flash(message, type) {
|
|
if (window.app && window.app.toast) {
|
|
window.app.toast.show(message, { type });
|
|
}
|
|
}
|
|
}
|
|
|
|
window.AiCorrection = AiCorrection;
|
|
export { AiCorrection };
|