chore: add docker infrastructure, gists feature, attachment system, and admin CLI tools

- Add .dockerignore, Dockerfile, and docker compose targets to Makefile for containerized deployment
- Implement gists router with CRUD operations, database schema, and polymorphic comment/vote reuse
- Create attachment upload system with thumbnail generation, MIME detection, and storage path management
- Add attachments_prune CLI command to clean orphaned attachment records and files
- Introduce rate limiting middleware with 60 requests per minute window
- Add custom 404 and 500 error handlers with SEO-optimized template responses
- Extend database initialization with gists and attachments indexes plus upload site settings defaults
- Update load_comments to include attachment mapping for comment resources
- Register gists and uploads routers in main application and update AGENTS.md documentation
This commit is contained in:
2026-05-12 13:07:34 +00:00
parent ff2585b098
commit aa88f18c03
69 changed files with 3069 additions and 450 deletions
+272
View File
@@ -0,0 +1,272 @@
.attachment-upload-zone {
border: 2px dashed var(--border-light);
border-radius: var(--radius);
padding: 1.5rem 1rem;
text-align: center;
cursor: pointer;
transition: all 0.2s;
background: var(--bg-input);
position: relative;
}
.attachment-upload-zone:hover {
border-color: var(--accent);
background: var(--accent-light);
}
.attachment-upload-zone.dragover {
border-color: var(--accent);
background: var(--accent-light);
border-style: solid;
}
.attachment-upload-zone input[type="file"] {
display: none;
}
.attachment-upload-zone .upload-icon {
font-size: 1.5rem;
margin-bottom: 0.5rem;
display: block;
}
.attachment-upload-zone .upload-text {
font-size: 0.8125rem;
color: var(--text-muted);
}
.attachment-upload-zone .upload-hint {
font-size: 0.75rem;
color: var(--text-muted);
margin-top: 0.375rem;
opacity: 0.7;
}
.attachment-upload-zone.uploading {
pointer-events: none;
opacity: 0.6;
}
.attachment-preview-list {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
margin-top: 0.75rem;
}
.attachment-preview {
position: relative;
width: 96px;
height: 96px;
border-radius: var(--radius);
border: 1px solid var(--border);
overflow: hidden;
background: var(--bg-card-hover);
}
.attachment-preview img {
width: 100%;
height: 100%;
object-fit: cover;
}
.attachment-preview .file-icon {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: 0.625rem;
color: var(--text-muted);
padding: 0.25rem;
text-align: center;
word-break: break-all;
}
.attachment-preview .file-icon .icon {
font-size: 1.5rem;
margin-bottom: 0.25rem;
}
.attachment-preview .file-size {
font-size: 0.625rem;
color: var(--text-muted);
margin-top: 0.125rem;
}
.attachment-preview .attachment-remove {
position: absolute;
top: 2px;
right: 2px;
width: 20px;
height: 20px;
border-radius: 50%;
background: rgba(0, 0, 0, 0.7);
color: #fff;
border: none;
font-size: 0.75rem;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
opacity: 0;
transition: opacity 0.2s;
}
.attachment-preview:hover .attachment-remove {
opacity: 1;
}
.attachment-progress {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 3px;
background: var(--bg-primary);
}
.attachment-progress-bar {
height: 100%;
background: var(--accent);
transition: width 0.3s;
}
.attachment-gallery {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
margin: 0.75rem 0;
}
.attachment-gallery-item {
position: relative;
width: 120px;
height: 120px;
border-radius: var(--radius);
border: 1px solid var(--border);
overflow: hidden;
cursor: pointer;
transition: transform 0.2s;
background: var(--bg-card-hover);
}
.attachment-gallery-item:hover {
transform: scale(1.05);
}
.attachment-gallery-item img {
width: 100%;
height: 100%;
object-fit: cover;
}
.attachment-gallery-item .non-image {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 0.5rem;
text-align: center;
text-decoration: none;
color: var(--text-secondary);
}
.attachment-gallery-item .non-image .icon {
font-size: 2rem;
margin-bottom: 0.25rem;
}
.attachment-gallery-item .non-image .name {
font-size: 0.6875rem;
word-break: break-all;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.attachment-gallery-item .non-image .size {
font-size: 0.625rem;
color: var(--text-muted);
}
.attachment-gallery-item .non-image:hover {
color: var(--accent);
}
.attachment-lightbox {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.9);
display: none;
align-items: center;
justify-content: center;
z-index: 10000;
cursor: pointer;
}
.attachment-lightbox.visible {
display: flex;
}
.attachment-lightbox img {
max-width: 90vw;
max-height: 90vh;
object-fit: contain;
border-radius: var(--radius);
}
.attachment-lightbox-close {
position: absolute;
top: 1rem;
right: 1rem;
width: 40px;
height: 40px;
border-radius: 50%;
background: rgba(255, 255, 255, 0.1);
color: #fff;
border: none;
font-size: 1.25rem;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
}
.attachment-upload-error {
font-size: 0.75rem;
color: var(--danger);
margin-top: 0.375rem;
}
.attachment-counter {
font-size: 0.75rem;
color: var(--text-muted);
margin-top: 0.25rem;
text-align: right;
}
.attachment-uploading-text {
font-size: 0.75rem;
color: var(--text-muted);
text-align: center;
margin-top: 0.5rem;
}
@media (max-width: 480px) {
.attachment-gallery-item {
width: 80px;
height: 80px;
}
.attachment-preview {
width: 72px;
height: 72px;
}
}
+322 -1
View File
@@ -1,4 +1,316 @@
@import url("variables.css");
.error-page {
text-align: center;
padding: 4rem 1rem;
}
.error-code {
font-size: 5rem;
font-weight: 800;
color: var(--accent);
line-height: 1;
margin-bottom: 0.5rem;
}
.error-message {
font-size: 1.125rem;
color: var(--text-secondary);
margin-bottom: 1.5rem;
}
.line-clamp-3 {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
.line-clamp-4 {
display: -webkit-box;
-webkit-line-clamp: 4;
-webkit-box-orient: vertical;
overflow: hidden;
}
.modal-card {
width: 100%;
max-width: 560px;
margin: 1rem;
max-height: 90vh;
overflow-y: auto;
}
.modal-card-wide {
max-width: 700px;
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
}
.modal-header h3 {
font-size: 1.125rem;
font-weight: 700;
}
.modal-close-btn {
font-size: 1.25rem;
}
.modal-footer {
display: flex;
gap: 0.75rem;
justify-content: flex-end;
}
.form-row {
display: flex;
gap: 0.375rem;
flex-wrap: wrap;
margin-bottom: 1rem;
}
.topic-label {
display: flex;
align-items: center;
gap: 0.25rem;
padding: 0.375rem 0.75rem;
border-radius: 999px;
font-size: 0.75rem;
font-weight: 600;
cursor: pointer;
background: var(--bg-card-hover);
transition: all 0.2s;
}
.topic-radio {
width: auto;
accent-color: var(--accent);
}
.inline-form {
display: inline;
}
.text-muted {
color: var(--text-muted);
}
.text-secondary {
color: var(--text-secondary);
}
.text-primary {
color: var(--text-primary);
}
.auth-field-gap {
margin-bottom: 0.75rem;
}
.load-more-wrap {
text-align: center;
margin-top: 1rem;
}
.top-authors-section {
margin-top: 0.75rem;
padding-top: 0.75rem;
border-top: 1px solid var(--border);
}
.top-authors-title {
font-size: 0.75rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.1em;
color: var(--text-muted);
margin-bottom: 0.5rem;
}
.no-authors-msg {
font-size: 0.75rem;
color: var(--text-muted);
padding: 0.5rem 0;
}
.no-comments-msg {
color: var(--text-muted);
font-size: 0.875rem;
text-align: center;
padding: 2rem 0;
}
.topic-wrap {
margin-bottom: 0.75rem;
}
.related-section {
margin-top: 1.5rem;
}
.related-list {
display: flex;
flex-direction: column;
gap: 0.75rem;
}
.related-link {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 0.25rem;
padding: 0.75rem;
width: 100%;
border-radius: var(--radius);
transition: background 0.2s;
}
.related-link:hover {
background: var(--bg-card);
}
.related-title {
color: var(--text-primary);
font-size: 0.875rem;
}
.related-meta {
color: var(--text-muted);
font-size: 0.75rem;
}
.v-align-middle {
vertical-align: middle;
}
.mr-0-375 {
margin-right: 0.375rem;
}
.flex-center {
display: flex;
align-items: center;
}
.flex-center-gap {
display: flex;
align-items: center;
gap: 0.5rem;
}
.flex-col-gap {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.full-width {
width: 100%;
}
.justify-center {
justify-content: center;
}
.grid-2col {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.75rem;
margin-bottom: 0.75rem;
}
.section-divider {
border: none;
border-top: 1px solid var(--border);
margin: 1.5rem 0;
}
.section-label {
font-size: 0.875rem;
font-weight: 700;
margin-bottom: 0.75rem;
color: var(--text-secondary);
}
.inline-flex {
display: inline-flex;
align-items: center;
gap: 0.375rem;
}
.input-sm {
font-size: 0.8125rem;
}
.min-h-100 {
min-height: 100px;
}
.min-h-120 {
min-height: 120px;
}
.min-h-200 {
min-height: 200px;
}
.flex-between {
display: flex;
justify-content: space-between;
align-items: center;
}
.flex-wrap-gap {
display: flex;
gap: 0.375rem;
flex-wrap: wrap;
}
.flex-wrap-gap-bottom {
display: flex;
flex-wrap: wrap;
gap: 0.375rem;
margin-bottom: 0.5rem;
}
.badge-type {
background: var(--border);
color: var(--text-muted);
text-transform: capitalize;
}
.empty-state-full {
grid-column: 1 / -1;
}
.projects-settings-btn {
margin-left: auto;
}
.auth-field-gap-last {
margin-bottom: 1rem;
}
.platform-presets-wrap {
display: flex;
flex-wrap: wrap;
gap: 0.25rem;
margin-top: 0.5rem;
}
.profile-actions {
margin-top: 1rem;
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.input-edit-field {
margin-bottom: 0.5rem;
}
.save-btn-top {
margin-top: 0.5rem;
}
.profile-tab-btn {
margin-left: auto;
font-size: 0.8125rem;
}
.post-action-static {
cursor: default;
}
.activity-card {
padding: 0.75rem 1rem;
}
.activity-row {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.8125rem;
}
.activity-icon {
color: var(--text-muted);
}
.activity-type {
color: var(--text-secondary);
}
.activity-time {
color: var(--text-muted);
}
.activity-content {
font-size: 0.8125rem;
color: var(--text-muted);
margin-top: 0.25rem;
}
.project-card {
display: block;
text-decoration: none;
color: inherit;
}
.gist-card {
display: block;
text-decoration: none;
color: inherit;
}
.platform-preset {
padding: 0.25rem 0.5rem;
border-radius: 4px;
font-size: 0.6875rem;
font-weight: 600;
background: var(--border);
color: var(--text-muted);
cursor: pointer;
border: none;
}
*, *::before, *::after {
box-sizing: border-box;
@@ -172,6 +484,8 @@ img {
overflow: hidden;
}
.avatar-24 { width: 24px; height: 24px; }
.avatar-xs { width: 20px; height: 20px; font-size: 0.6875rem; }
.avatar-sm { width: 32px; height: 32px; font-size: 0.8125rem; }
.avatar-lg { width: 80px; height: 80px; font-size: 2rem; }
.avatar-img { border-radius: 50%; object-fit: cover; flex-shrink: 0; }
@@ -308,6 +622,13 @@ img {
color: var(--accent);
}
.icon {
font-size: 1rem;
width: 20px;
text-align: center;
flex-shrink: 0;
}
.back-link {
display: inline-flex;
align-items: center;
-6
View File
@@ -5,12 +5,6 @@
align-items: start;
}
.sidebar-link[data-topic="devlog"] .sidebar-dot { background: var(--topic-devlog); }
.sidebar-link[data-topic="showcase"] .sidebar-dot { background: var(--topic-showcase); }
.sidebar-link[data-topic="question"] .sidebar-dot { background: var(--topic-question); }
.sidebar-link[data-topic="rant"] .sidebar-dot { background: var(--topic-rant); }
.sidebar-link[data-topic="fun"] .sidebar-dot { background: var(--topic-fun); }
.sidebar-link[data-topic="signals"] .sidebar-dot { background: var(--topic-signals); }
.feed-nav {
display: flex;
+292
View File
@@ -0,0 +1,292 @@
.gists-layout {
display: grid;
grid-template-columns: var(--sidebar-width) 1fr;
gap: 1.5rem;
align-items: start;
}
.gists-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 1rem;
}
.gists-header h1 {
font-size: 1.5rem;
font-weight: 700;
}
.gists-count {
font-size: 0.8125rem;
color: var(--text-muted);
}
.gists-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
gap: 1rem;
}
.gist-card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
padding: 1.25rem;
transition: all 0.2s;
}
a.gist-card {
display: block;
text-decoration: none;
color: inherit;
}
.gist-card:hover {
border-color: var(--border-light);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.gist-card-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 0.75rem;
margin-bottom: 0.5rem;
}
.gist-card-title {
font-size: 1rem;
font-weight: 700;
color: var(--text-primary);
line-height: 1.3;
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.gist-card-meta {
display: flex;
align-items: center;
gap: 0.75rem;
font-size: 0.75rem;
color: var(--text-muted);
margin-bottom: 0.75rem;
}
.gist-card-desc {
font-size: 0.8125rem;
color: var(--text-secondary);
line-height: 1.5;
margin-bottom: 0.75rem;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
.gist-language-badge {
display: inline-flex;
align-items: center;
gap: 0.25rem;
padding: 0.125rem 0.5rem;
border-radius: 999px;
font-size: 0.6875rem;
font-weight: 600;
color: var(--text-primary);
background: rgba(255, 107, 53, 0.15);
}
.gist-card-star {
display: inline-flex;
align-items: center;
gap: 0.25rem;
font-size: 0.75rem;
color: var(--text-muted);
transition: color 0.2s;
}
.gist-card-star:hover {
color: var(--warning);
}
.gist-card-footer {
display: flex;
align-items: center;
justify-content: space-between;
padding-top: 0.75rem;
border-top: 1px solid var(--border);
}
.gist-author {
display: flex;
align-items: center;
gap: 0.375rem;
font-size: 0.75rem;
color: var(--text-muted);
}
.gist-author img {
width: 20px;
height: 20px;
border-radius: 50%;
}
.gist-detail-page {
max-width: 860px;
margin: 0 auto;
}
.gist-detail {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
padding: 1.5rem;
}
.gist-detail-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 1rem;
margin-bottom: 1rem;
}
.gist-detail-title {
font-size: 1.5rem;
font-weight: 700;
line-height: 1.3;
}
.gist-detail-author {
display: flex;
align-items: center;
gap: 0.5rem;
margin-bottom: 1rem;
padding-bottom: 1rem;
border-bottom: 1px solid var(--border);
}
.gist-detail-author a {
font-weight: 600;
font-size: 0.875rem;
color: var(--text-primary);
}
.gist-detail-desc {
font-size: 0.9375rem;
color: var(--text-secondary);
line-height: 1.7;
margin-bottom: 1.5rem;
}
.gist-code-block {
margin-bottom: 1.5rem;
border: 1px solid var(--border);
border-radius: var(--radius);
overflow: hidden;
}
.gist-code-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0.5rem 0.75rem;
background: var(--bg-secondary);
border-bottom: 1px solid var(--border);
font-size: 0.75rem;
font-weight: 600;
color: var(--text-muted);
}
.gist-code-header .gist-language-name {
text-transform: uppercase;
letter-spacing: 0.05em;
}
.gist-code-header .gist-copy-btn {
background: none;
border: none;
color: var(--text-muted);
cursor: pointer;
font-size: 0.75rem;
padding: 0.25rem 0.5rem;
border-radius: var(--radius);
transition: all 0.2s;
}
.gist-code-header .gist-copy-btn:hover {
background: var(--bg-card-hover);
color: var(--text-primary);
}
.gist-code-block pre {
margin: 0;
padding: 1rem;
overflow-x: auto;
background: #1a1a2e;
font-size: 0.8125rem;
line-height: 1.5;
}
.gist-code-block pre code {
background: none;
padding: 0;
font-family: var(--font-mono);
}
.gist-detail-actions {
display: flex;
align-items: center;
gap: 0.5rem;
padding-top: 1rem;
border-top: 1px solid var(--border);
}
.gist-star-btn {
display: inline-flex;
align-items: center;
gap: 0.375rem;
padding: 0.375rem 0.75rem;
border-radius: var(--radius);
font-size: 0.8125rem;
font-weight: 500;
color: var(--text-muted);
background: none;
border: none;
cursor: pointer;
transition: all 0.2s;
}
.gist-star-btn:hover {
background: var(--bg-card-hover);
color: var(--warning);
}
.CodeMirror {
height: auto;
min-height: 300px;
border: 1px solid var(--border);
border-radius: var(--radius);
font-size: 0.8125rem;
}
.CodeMirror-gutters {
border-right: 1px solid var(--border);
background: var(--bg-secondary);
}
.CodeMirror-linenumber {
color: var(--text-muted);
}
@media (max-width: 768px) {
.gists-layout {
grid-template-columns: 1fr;
}
.gists-grid {
grid-template-columns: 1fr;
}
}
+42
View File
@@ -0,0 +1,42 @@
.mention-wrapper {
position: relative;
width: 100%;
}
.mention-dropdown {
display: none;
position: absolute;
bottom: 100%;
left: 0;
right: 0;
background: var(--bg-secondary);
border: 1px solid var(--border);
border-radius: var(--radius);
box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.3);
z-index: 2100;
max-height: 200px;
overflow-y: auto;
margin-bottom: 4px;
}
.mention-dropdown-item {
display: flex;
align-items: center;
gap: 0.625rem;
width: 100%;
padding: 0.5rem 0.75rem;
font-size: 0.875rem;
color: var(--text-primary);
background: none;
border: none;
cursor: pointer;
text-align: left;
font-family: inherit;
transition: background 0.1s;
}
.mention-dropdown-item:hover,
.mention-dropdown-item.active {
background: var(--accent-light);
color: var(--accent);
}
+1
View File
@@ -1,6 +1,7 @@
.notifications-page {
max-width: 640px;
margin: 0 auto;
padding-top: var(--nav-height);
}
.notifications-header {
+75
View File
@@ -0,0 +1,75 @@
.sidebar-card {
position: sticky;
top: calc(var(--nav-height) + 1rem);
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
padding: 1rem;
}
.sidebar-card .sidebar-heading {
font-size: 0.75rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.1em;
color: var(--text-muted);
margin-bottom: 0.75rem;
}
.sidebar-section {
margin-bottom: 1rem;
}
.sidebar-section:last-child {
margin-bottom: 0;
}
.sidebar-nav {
display: flex;
flex-direction: column;
gap: 0.125rem;
}
.sidebar-link {
display: flex;
align-items: center;
gap: 0.625rem;
padding: 0.5rem 0.75rem;
border-radius: var(--radius);
font-size: 0.875rem;
color: var(--text-secondary);
transition: all 0.2s;
}
.sidebar-link:hover {
background: var(--bg-card-hover);
color: var(--text-primary);
text-decoration: none;
}
.sidebar-link.active,
.sidebar-link.active:hover {
background: var(--accent-light);
color: var(--accent);
font-weight: 600;
}
.sidebar-dot {
width: 8px;
height: 8px;
border-radius: 50%;
flex-shrink: 0;
}
.sidebar-icon {
font-size: 1rem;
width: 20px;
text-align: center;
flex-shrink: 0;
}
@media (max-width: 1024px) {
.sidebar-card {
display: none;
}
}
+149 -5
View File
@@ -14,6 +14,15 @@ class Application {
this.initCommentReply();
this.initEmojiPickers();
this.initMentionInputs();
this.initConfirmations();
this.initImageFallbacks();
this.initClipboardCopy();
this.initAutoSubmitSelects();
this.initTogglers();
this.initStopPropagation();
this.initMessageThread();
this.initPlatformTags();
this.initAttachmentUploaders();
}
loadCSS(href) {
@@ -238,9 +247,9 @@ class Application {
initContentRenderer() {
document.querySelectorAll("[data-render]").forEach((el) => {
contentRenderer.applyTo(el);
window.contentRenderer.applyTo(el);
});
contentRenderer.highlightAll();
window.contentRenderer.highlightAll();
}
initCommentReply() {
@@ -271,11 +280,145 @@ class Application {
}
initMentionInputs() {
if (typeof MentionInput === "undefined") return;
if (!window.MentionInput) return;
document.querySelectorAll("[data-mention]").forEach((el) => {
if (el.dataset.mentionInitialized) return;
el.dataset.mentionInitialized = "true";
new MentionInput(el);
new window.MentionInput(el);
});
}
initConfirmations() {
document.querySelectorAll("[data-confirm]").forEach((btn) => {
btn.addEventListener("click", (e) => {
if (!confirm(btn.dataset.confirm)) {
e.preventDefault();
}
});
});
}
initImageFallbacks() {
document.querySelectorAll(".image-fallback").forEach((img) => {
img.addEventListener("error", () => {
const container = img.closest(".news-card-image, .news-detail-image") || img.parentElement;
if (container) container.style.display = "none";
});
});
}
initClipboardCopy() {
document.querySelectorAll("[data-copy]").forEach((btn) => {
btn.addEventListener("click", async () => {
const source = document.getElementById(btn.dataset.copy);
if (!source) return;
try {
await navigator.clipboard.writeText(source.textContent);
const original = btn.textContent;
btn.textContent = "Copied!";
setTimeout(() => { btn.textContent = original; }, 2000);
} catch {
// silently fail
}
});
});
}
initAutoSubmitSelects() {
document.querySelectorAll("[data-auto-submit]").forEach((select) => {
select.addEventListener("change", () => {
const form = select.closest("form");
if (form) form.submit();
});
});
}
initTogglers() {
document.querySelectorAll("[data-toggle]").forEach((btn) => {
btn.addEventListener("click", () => {
const target = document.getElementById(btn.dataset.toggle);
if (target) target.classList.toggle("hidden");
});
});
}
initStopPropagation() {
document.querySelectorAll("[data-stop-propagation]").forEach((el) => {
el.addEventListener("click", (e) => e.stopPropagation());
});
}
initMessageThread() {
const thread = document.querySelector(".messages-thread");
if (thread) thread.scrollTop = thread.scrollHeight;
}
initPlatformTags() {
const platformsInput = document.getElementById("platforms-input");
const hiddenInput = document.getElementById("platforms");
const tagsContainer = document.getElementById("platforms-tags");
if (!platformsInput || !hiddenInput || !tagsContainer) return;
const addPlatform = (val) => {
val = val.trim();
if (!val) return;
const tag = document.createElement("span");
tag.className = "platform-tag";
tag.textContent = val;
const remove = document.createElement("button");
remove.type = "button";
remove.textContent = "x";
remove.style.marginLeft = "4px";
remove.style.fontSize = "0.75rem";
remove.style.padding = "0";
remove.style.background = "none";
remove.style.border = "none";
remove.style.color = "inherit";
remove.style.cursor = "pointer";
remove.addEventListener("click", () => {
tag.remove();
updatePlatforms();
});
tag.appendChild(remove);
tagsContainer.appendChild(tag);
platformsInput.value = "";
updatePlatforms();
};
const updatePlatforms = () => {
const values = [];
tagsContainer.querySelectorAll(".platform-tag").forEach((t) => {
values.push(t.textContent.replace("x", "").trim());
});
hiddenInput.value = values.join(",");
};
platformsInput.addEventListener("keydown", (e) => {
if (e.key === "Enter") {
e.preventDefault();
addPlatform(platformsInput.value);
}
});
document.querySelectorAll(".platform-preset").forEach((btn) => {
btn.addEventListener("click", () => {
addPlatform(btn.dataset.platform);
});
});
}
initAttachmentManagers() {
if (!window.AttachmentUploader) return;
document.querySelectorAll(".attachment-upload-container").forEach((container) => {
if (container.dataset.attachmentInitialized) return;
container.dataset.attachmentInitialized = "true";
const form = container.closest("form");
if (form) {
form.dataset.maxSize = container.dataset.maxSize;
form.dataset.maxFiles = container.dataset.maxFiles;
form.dataset.allowedTypes = container.dataset.allowedTypes || "";
new window.AttachmentUploader(form);
}
});
}
@@ -290,7 +433,7 @@ class Application {
btn.title = "Add emoji";
btn.innerHTML = "\u{1F600}";
const picker = new EmojiPicker(textarea);
const picker = new window.EmojiPicker(textarea);
btn.addEventListener("click", () => picker.toggle());
const parent = textarea.parentElement;
@@ -307,3 +450,4 @@ class Application {
}
const app = new Application();
window.app = app;
+7 -8
View File
@@ -68,9 +68,8 @@ class ContentRenderer {
const parts = [];
let lastIndex = 0;
const urlRe = /(https?:\/\/[^\s<]+)/g;
const mentionRe = /(?:^|[\s(])@([a-zA-Z0-9_-]+)/g;
const mentionRe = /(?:^|\s|\x28)@([a-zA-Z0-9_-]+)/g;
let match;
let mentionMatch;
while ((match = urlRe.exec(text)) !== null) {
if (match.index > lastIndex) {
@@ -93,9 +92,9 @@ class ContentRenderer {
fragment.appendChild(document.createTextNode(part.value));
} else if (part.type === "mention") {
const a = document.createElement("a");
a.href = `/profile/${part.username}`;
a.href = "/profile/" + part.username;
a.className = "mention-link";
a.textContent = `@${part.username}`;
a.textContent = "@" + part.username;
fragment.appendChild(a);
} else {
const el = this.urlToEmbed(part.value);
@@ -119,7 +118,7 @@ class ContentRenderer {
}
splitMentions(text, parts) {
const mentionRe = /(?:^|[\s(])@([a-zA-Z0-9_-]+)/g;
const mentionRe = /(?:^|\s|\x28)@([a-zA-Z0-9_-]+)/g;
let m;
let last = 0;
while ((m = mentionRe.exec(text)) !== null) {
@@ -127,10 +126,10 @@ class ContentRenderer {
parts.push({ type: "text", value: text.substring(last, m.index) });
}
const prefix = m[0][0];
if (prefix && /\S/.test(prefix)) {
if (prefix) {
parts.push({ type: "text", value: prefix });
}
parts.push({ type: "mention", username: m[1], value: m[0] });
parts.push({ type: "mention", username: m[1] });
last = m.index + m[0].length;
}
if (last < text.length) {
@@ -195,4 +194,4 @@ class ContentRenderer {
}
}
const contentRenderer = new ContentRenderer();
window.contentRenderer = new ContentRenderer();
+1
View File
@@ -58,3 +58,4 @@ class EmojiPicker {
this.wrapper.style.display = "none";
}
}
window.EmojiPicker = EmojiPicker;
+71
View File
@@ -0,0 +1,71 @@
class GistEditor {
constructor() {
this.editor = null;
this.init();
}
init() {
if (typeof CodeMirror === "undefined") return;
const textarea = document.getElementById("gist-source-editor");
if (!textarea || textarea.dataset.cminit) return;
textarea.dataset.cminit = "1";
this.editor = CodeMirror.fromTextArea(textarea, {
lineNumbers: true,
mode: textarea.dataset.language || "plaintext",
theme: "monokai",
indentUnit: 4,
tabSize: 4,
lineWrapping: true,
extraKeys: {
"Ctrl-S": () => {
const form = textarea.closest("form");
if (form) {
this.editor.save();
form.submit();
}
},
},
});
this.editor.setSize(null, 400);
const langSelect = document.getElementById("gist-language");
if (langSelect) {
langSelect.addEventListener("change", () => {
let mode = langSelect.value;
const modeMap = {
"c": "text/x-csrc",
"cpp": "text/x-c++src",
"java": "text/x-java",
"bash": "text/x-sh",
"ruby": "text/x-ruby",
"php": "text/x-php",
"perl": "text/x-perl",
"haskell": "text/x-haskell",
"lua": "text/x-lua",
"elixir": "text/x-elixir",
"dart": "text/x-dart",
"r": "text/x-rsrc",
"scala": "text/x-scala",
};
this.editor.setOption("mode", modeMap[mode] || mode);
});
}
const form = textarea.closest("form");
if (form) {
form.addEventListener("submit", () => {
this.editor.save();
});
}
}
refresh() {
if (this.editor) {
setTimeout(() => this.editor.refresh(), 100);
}
}
}
window.GistEditor = GistEditor;
+133
View File
@@ -0,0 +1,133 @@
class MentionInput {
constructor(element) {
this.input = element;
this.dropdown = null;
this.debounceTimer = null;
this.selectedIndex = -1;
this.lastMatch = null;
this.build();
}
build() {
const wrap = document.createElement("div");
wrap.className = "mention-wrapper";
this.input.parentNode.insertBefore(wrap, this.input);
wrap.appendChild(this.input);
this.dropdown = document.createElement("div");
this.dropdown.className = "mention-dropdown";
wrap.appendChild(this.dropdown);
this.input.addEventListener("input", () => this.onInput());
this.input.addEventListener("keydown", (e) => this.onKeydown(e));
this.input.addEventListener("blur", () => {
setTimeout(() => { this.dropdown.style.display = "none"; }, 200);
});
}
onInput() {
clearTimeout(this.debounceTimer);
const pos = this.input.selectionStart;
const text = this.input.value.substring(0, pos);
let match = text.match(/(?:^|\s|\x28)@([a-zA-Z0-9_-]*)$/);
if (!match) {
this.dropdown.style.display = "none";
this.lastMatch = null;
return;
}
const query = match[1];
this.lastMatch = { query, index: match.index + (text[match.index] === "@" ? 0 : 1) };
if (query.length < 1) {
this.dropdown.style.display = "none";
return;
}
this.debounceTimer = setTimeout(() => this.fetch(query), 200);
}
async fetch(query) {
try {
const resp = await fetch("/profile/search?q=" + encodeURIComponent(query));
const data = await resp.json();
const results = data.results || [];
if (results.length === 0) {
this.dropdown.style.display = "none";
return;
}
this.render(results);
} catch (e) {
this.dropdown.style.display = "none";
}
}
render(results) {
this.dropdown.innerHTML = "";
this.selectedIndex = -1;
for (const r of results) {
const item = document.createElement("button");
item.type = "button";
item.className = "mention-dropdown-item";
item.dataset.username = r.username;
item.innerHTML = '<img src="/avatar/multiavatar/' + encodeURIComponent(r.username) + '?size=24" class="avatar-img" style="width:24px;height:24px;border-radius:50%" alt="" loading="lazy"><span>@' + r.username + '</span>';
item.addEventListener("mousedown", (e) => {
e.preventDefault();
this.insert(r.username);
});
this.dropdown.appendChild(item);
}
this.dropdown.style.display = "block";
}
onKeydown(e) {
const items = this.dropdown.querySelectorAll(".mention-dropdown-item");
if (this.dropdown.style.display !== "block" || items.length === 0) {
return;
}
if (e.key === "ArrowDown") {
e.preventDefault();
this.selectedIndex = Math.min(this.selectedIndex + 1, items.length - 1);
this.highlight(items);
} else if (e.key === "ArrowUp") {
e.preventDefault();
this.selectedIndex = Math.max(this.selectedIndex - 1, 0);
this.highlight(items);
} else if (e.key === "Enter" || e.key === "Tab") {
if (this.selectedIndex >= 0 && items[this.selectedIndex]) {
e.preventDefault();
this.insert(items[this.selectedIndex].dataset.username);
}
} else if (e.key === "Escape") {
this.dropdown.style.display = "none";
}
}
highlight(items) {
items.forEach((item, i) => {
item.classList.toggle("active", i === this.selectedIndex);
});
if (this.selectedIndex >= 0 && items[this.selectedIndex]) {
items[this.selectedIndex].scrollIntoView({ block: "nearest" });
}
}
insert(username) {
if (!this.lastMatch) return;
const val = this.input.value;
let before = val.substring(0, this.lastMatch.index);
let after = val.substring(this.lastMatch.index + this.lastMatch.query.length + 1);
before = before.replace(/@+$/, "");
after = after.replace(/^@+/, "");
this.input.value = before + "@" + username + " " + after;
const newPos = before.length + username.length + 2;
this.input.setSelectionRange(newPos, newPos);
this.input.focus();
this.input.dispatchEvent(new Event("input", { bubbles: true }));
this.dropdown.style.display = "none";
this.lastMatch = null;
}
}
window.MentionInput = MentionInput;
+60
View File
@@ -0,0 +1,60 @@
class ServiceMonitor {
constructor() {
this.pollInterval = 5000;
}
start() {
this.pollServices();
setInterval(() => this.pollServices(), this.pollInterval);
}
formatDate(isoStr, includeTime) {
if (!isoStr) return "-";
try {
const d = new Date(isoStr);
if (isNaN(d.getTime())) return isoStr.slice(0, 19);
const dd = String(d.getDate()).padStart(2, "0");
const mm = String(d.getMonth() + 1).padStart(2, "0");
const yyyy = d.getFullYear();
if (includeTime) {
const hh = String(d.getHours()).padStart(2, "0");
const mi = String(d.getMinutes()).padStart(2, "0");
return `${dd}/${mm}/${yyyy} ${hh}:${mi}`;
}
return `${dd}/${mm}/${yyyy}`;
} catch {
return isoStr.slice(0, 19);
}
}
async pollServices() {
try {
const resp = await fetch("/admin/services/data");
const data = await resp.json();
const container = document.getElementById("services-list");
if (!container) return;
for (const svc of data.services) {
const card = container.querySelector(`.service-card[data-service="${svc.name}"]`);
if (!card) continue;
const statusEl = card.querySelector(".service-status");
if (statusEl) {
statusEl.textContent = svc.status;
statusEl.className = "service-status " + svc.status;
}
const metaItems = card.querySelectorAll(".meta-item");
if (metaItems.length >= 3) {
metaItems[0].textContent = "Uptime: " + (svc.uptime || "-");
metaItems[1].textContent = "Last run: " + this.formatDate(svc.last_run, true);
metaItems[2].textContent = "Next run: " + this.formatDate(svc.next_run, true);
}
const logPre = card.querySelector(".log-output");
if (logPre) {
logPre.textContent = (svc.log_buffer || []).map((l) => l + "\n").join("") || "No log entries yet.\n";
}
}
} catch {
// silently ignore poll errors
}
}
}
window.ServiceMonitor = ServiceMonitor;