Initial commit: Lookbook personal collection app
Pinterest-like app for saving images, videos, quotes, and embeds. Features: - Go backend with PostgreSQL, SSR templates - Console-based admin auth (login/logout via browser console) - Item types: images, videos (ffmpeg transcoding), quotes, embeds - Media stored as BLOBs in PostgreSQL - OpenGraph metadata extraction for links - Embed detection for YouTube, Vimeo, Twitter/X - Masonry grid layout, item detail pages - Tag system with filtering - Refresh metadata endpoint with change warnings - Replace media endpoint for updating item images/videos
This commit is contained in:
commit
cdcc5b5293
45 changed files with 4634 additions and 0 deletions
0
internal/static/css/.gitkeep
Normal file
0
internal/static/css/.gitkeep
Normal file
562
internal/static/css/app.css
Normal file
562
internal/static/css/app.css
Normal file
|
|
@ -0,0 +1,562 @@
|
|||
/*
|
||||
* Commit Mono - Neutral programming typeface
|
||||
* Licensed under SIL Open Font License 1.1
|
||||
* https://commitmono.com/
|
||||
*/
|
||||
|
||||
@font-face {
|
||||
font-family: 'CommitMono';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
font-display: swap;
|
||||
src: url("../fonts/CommitMono-450-Regular.woff2") format('woff2');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'CommitMono';
|
||||
font-style: italic;
|
||||
font-weight: 400;
|
||||
font-display: swap;
|
||||
src: url("../fonts/CommitMono-450-Italic.woff2") format('woff2');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'CommitMono';
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
font-display: swap;
|
||||
src: url("../fonts/CommitMono-700-Regular.woff2") format('woff2');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'CommitMono';
|
||||
font-style: italic;
|
||||
font-weight: 700;
|
||||
font-display: swap;
|
||||
src: url("../fonts/CommitMono-700-Italic.woff2") format('woff2');
|
||||
}
|
||||
|
||||
/* Reset */
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* Base */
|
||||
:root {
|
||||
--bg: #fff;
|
||||
--fg: #000;
|
||||
--gray-1: #f5f5f5;
|
||||
--gray-2: #e5e5e5;
|
||||
--gray-3: #888;
|
||||
--font: 'CommitMono', ui-monospace, 'SF Mono', Menlo, monospace;
|
||||
}
|
||||
|
||||
html {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: var(--font);
|
||||
background: var(--bg);
|
||||
color: var(--fg);
|
||||
line-height: 1.5;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
img, video {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
display: block;
|
||||
}
|
||||
|
||||
button, input, textarea, select {
|
||||
font: inherit;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
/* Header */
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 1rem 2rem;
|
||||
border-bottom: 1px solid var(--gray-2);
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-weight: 700;
|
||||
font-size: 1rem;
|
||||
letter-spacing: 0.1em;
|
||||
}
|
||||
|
||||
.nav {
|
||||
display: flex;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.nav a {
|
||||
font-size: 0.85rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
/* Main */
|
||||
.main {
|
||||
max-width: 1600px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
/* Admin Bar */
|
||||
.admin-bar {
|
||||
margin-bottom: 1.5rem;
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
/* Tags Bar */
|
||||
.tags-bar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 2rem;
|
||||
padding-bottom: 1rem;
|
||||
border-bottom: 1px solid var(--gray-2);
|
||||
}
|
||||
|
||||
.tag {
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
padding: 0.25rem 0.5rem;
|
||||
border: 1px solid var(--gray-2);
|
||||
background: var(--bg);
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
.tag:hover, .tag.active {
|
||||
background: var(--fg);
|
||||
color: var(--bg);
|
||||
border-color: var(--fg);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* Grid */
|
||||
.grid {
|
||||
column-count: 4;
|
||||
column-gap: 1rem;
|
||||
}
|
||||
|
||||
.grid-item {
|
||||
display: block;
|
||||
break-inside: avoid;
|
||||
margin-bottom: 1rem;
|
||||
background: var(--gray-1);
|
||||
border: 1px solid var(--gray-2);
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
transition: transform 0.15s ease, box-shadow 0.15s ease;
|
||||
}
|
||||
|
||||
.grid-item:hover {
|
||||
text-decoration: none;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.grid-item img {
|
||||
width: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Quote Card */
|
||||
.quote-card {
|
||||
padding: 1.5rem;
|
||||
min-height: 150px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.quote-card blockquote {
|
||||
font-size: 1.1rem;
|
||||
font-style: italic;
|
||||
line-height: 1.6;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.quote-card blockquote::before {
|
||||
content: '"';
|
||||
}
|
||||
|
||||
.quote-card blockquote::after {
|
||||
content: '"';
|
||||
}
|
||||
|
||||
.quote-card cite {
|
||||
font-size: 0.85rem;
|
||||
color: var(--gray-3);
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* Link Card */
|
||||
.link-card {
|
||||
padding: 1.5rem;
|
||||
min-height: 100px;
|
||||
}
|
||||
|
||||
.link-title {
|
||||
font-weight: 700;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.link-url {
|
||||
font-size: 0.75rem;
|
||||
color: var(--gray-3);
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
/* Embed Placeholder */
|
||||
.embed-placeholder {
|
||||
aspect-ratio: 16/9;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--fg);
|
||||
color: var(--bg);
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
/* Item Tags */
|
||||
.item-tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.25rem;
|
||||
padding: 0.5rem;
|
||||
background: var(--bg);
|
||||
border-top: 1px solid var(--gray-2);
|
||||
}
|
||||
|
||||
.item-tag {
|
||||
font-size: 0.65rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
padding: 0.15rem 0.35rem;
|
||||
background: var(--gray-1);
|
||||
border: 1px solid var(--gray-2);
|
||||
}
|
||||
|
||||
/* Item Page */
|
||||
.item-page {
|
||||
max-width: 900px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.back-link {
|
||||
display: inline-block;
|
||||
font-size: 0.85rem;
|
||||
margin-bottom: 2rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.item-detail {
|
||||
border: 1px solid var(--gray-2);
|
||||
}
|
||||
|
||||
.image-container img,
|
||||
.video-container video {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.embed-container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* YouTube/Vimeo iframe embeds */
|
||||
.embed-container iframe {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
/* Twitter embeds */
|
||||
.embed-container .twitter-tweet {
|
||||
margin: 1rem auto !important;
|
||||
}
|
||||
|
||||
.quote-detail {
|
||||
padding: 3rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.quote-detail blockquote {
|
||||
font-size: 1.5rem;
|
||||
font-style: italic;
|
||||
line-height: 1.6;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.quote-detail blockquote::before {
|
||||
content: '"';
|
||||
}
|
||||
|
||||
.quote-detail blockquote::after {
|
||||
content: '"';
|
||||
}
|
||||
|
||||
.quote-detail cite {
|
||||
color: var(--gray-3);
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
.item-meta {
|
||||
padding: 1.5rem;
|
||||
border-top: 1px solid var(--gray-2);
|
||||
}
|
||||
|
||||
.item-meta h1 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.item-meta .description {
|
||||
margin-bottom: 1rem;
|
||||
color: var(--gray-3);
|
||||
}
|
||||
|
||||
.item-meta .source-link {
|
||||
display: block;
|
||||
font-size: 0.85rem;
|
||||
color: var(--gray-3);
|
||||
word-break: break-all;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.item-meta .item-tags {
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.item-meta .timestamp {
|
||||
display: block;
|
||||
font-size: 0.75rem;
|
||||
color: var(--gray-3);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.item-actions {
|
||||
padding: 1rem 1.5rem;
|
||||
border-top: 1px solid var(--gray-2);
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
.btn {
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.1em;
|
||||
padding: 0.5rem 1rem;
|
||||
border: 1px solid var(--fg);
|
||||
background: var(--bg);
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background: var(--fg);
|
||||
color: var(--bg);
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
border-color: #c00;
|
||||
color: #c00;
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
background: #c00;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-close {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 1.5rem;
|
||||
cursor: pointer;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
/* Modal */
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0,0,0,0.5);
|
||||
z-index: 1000;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.modal.active {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background: var(--bg);
|
||||
width: 90%;
|
||||
max-width: 500px;
|
||||
max-height: 90vh;
|
||||
overflow-y: auto;
|
||||
border: 1px solid var(--fg);
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 1rem 1.5rem;
|
||||
border-bottom: 1px solid var(--gray-2);
|
||||
}
|
||||
|
||||
.modal-header h2 {
|
||||
font-size: 1rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.1em;
|
||||
}
|
||||
|
||||
.modal-tabs {
|
||||
display: flex;
|
||||
border-bottom: 1px solid var(--gray-2);
|
||||
}
|
||||
|
||||
.modal-tabs .tab {
|
||||
flex: 1;
|
||||
padding: 0.75rem;
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.1em;
|
||||
cursor: pointer;
|
||||
border-bottom: 2px solid transparent;
|
||||
}
|
||||
|
||||
.modal-tabs .tab.active {
|
||||
border-bottom-color: var(--fg);
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.tab-content {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.tab-content.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Forms */
|
||||
form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
input, textarea {
|
||||
width: 100%;
|
||||
padding: 0.75rem;
|
||||
border: 1px solid var(--gray-2);
|
||||
background: var(--bg);
|
||||
}
|
||||
|
||||
input:focus, textarea:focus {
|
||||
outline: none;
|
||||
border-color: var(--fg);
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: vertical;
|
||||
min-height: 80px;
|
||||
}
|
||||
|
||||
input[type="file"] {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
/* Preview */
|
||||
.preview {
|
||||
padding: 1rem;
|
||||
background: var(--gray-1);
|
||||
border: 1px solid var(--gray-2);
|
||||
display: none;
|
||||
}
|
||||
|
||||
.preview.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.preview img {
|
||||
max-width: 200px;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.preview-title {
|
||||
font-weight: 700;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.preview-description {
|
||||
font-size: 0.85rem;
|
||||
color: var(--gray-3);
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 1200px) {
|
||||
.grid {
|
||||
column-count: 3;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.grid {
|
||||
column-count: 2;
|
||||
}
|
||||
|
||||
.main {
|
||||
padding: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.grid {
|
||||
column-count: 1;
|
||||
}
|
||||
|
||||
.header {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.quote-detail {
|
||||
padding: 2rem 1rem;
|
||||
}
|
||||
|
||||
.quote-detail blockquote {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
}
|
||||
BIN
internal/static/fonts/CommitMono-400-Italic.woff2
Normal file
BIN
internal/static/fonts/CommitMono-400-Italic.woff2
Normal file
Binary file not shown.
BIN
internal/static/fonts/CommitMono-400-Regular.woff2
Normal file
BIN
internal/static/fonts/CommitMono-400-Regular.woff2
Normal file
Binary file not shown.
BIN
internal/static/fonts/CommitMono-450-Italic.woff2
Normal file
BIN
internal/static/fonts/CommitMono-450-Italic.woff2
Normal file
Binary file not shown.
BIN
internal/static/fonts/CommitMono-450-Regular.woff2
Normal file
BIN
internal/static/fonts/CommitMono-450-Regular.woff2
Normal file
Binary file not shown.
BIN
internal/static/fonts/CommitMono-700-Italic.woff2
Normal file
BIN
internal/static/fonts/CommitMono-700-Italic.woff2
Normal file
Binary file not shown.
BIN
internal/static/fonts/CommitMono-700-Regular.woff2
Normal file
BIN
internal/static/fonts/CommitMono-700-Regular.woff2
Normal file
Binary file not shown.
0
internal/static/js/.gitkeep
Normal file
0
internal/static/js/.gitkeep
Normal file
386
internal/static/js/app.js
Normal file
386
internal/static/js/app.js
Normal file
|
|
@ -0,0 +1,386 @@
|
|||
// Console-based authentication
|
||||
window.login = async (password) => {
|
||||
if (!password) {
|
||||
console.error('Usage: login("your-password")');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const res = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ password })
|
||||
});
|
||||
const data = await res.json();
|
||||
if (res.ok) {
|
||||
console.log(data.firstTime ? 'Password set! Reloading...' : 'Logged in! Reloading...');
|
||||
setTimeout(() => location.reload(), 500);
|
||||
} else {
|
||||
console.error(data.error || 'Login failed');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Login error:', err);
|
||||
}
|
||||
};
|
||||
|
||||
window.logout = async () => {
|
||||
try {
|
||||
await fetch('/api/auth/logout', { method: 'POST' });
|
||||
console.log('Logged out! Reloading...');
|
||||
setTimeout(() => location.reload(), 500);
|
||||
} catch (err) {
|
||||
console.error('Logout error:', err);
|
||||
}
|
||||
};
|
||||
|
||||
// Modal functions
|
||||
function showAddModal() {
|
||||
document.getElementById('add-modal').classList.add('active');
|
||||
}
|
||||
|
||||
function hideAddModal() {
|
||||
document.getElementById('add-modal').classList.remove('active');
|
||||
}
|
||||
|
||||
function showEditModal() {
|
||||
document.getElementById('edit-modal').classList.add('active');
|
||||
}
|
||||
|
||||
function hideEditModal() {
|
||||
document.getElementById('edit-modal').classList.remove('active');
|
||||
}
|
||||
|
||||
// Tab switching
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const tabs = document.querySelectorAll('.modal-tabs .tab');
|
||||
tabs.forEach(tab => {
|
||||
tab.addEventListener('click', () => {
|
||||
const tabId = tab.dataset.tab;
|
||||
|
||||
// Update tab buttons
|
||||
tabs.forEach(t => t.classList.remove('active'));
|
||||
tab.classList.add('active');
|
||||
|
||||
// Update tab content
|
||||
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
|
||||
document.getElementById('tab-' + tabId).classList.add('active');
|
||||
});
|
||||
});
|
||||
|
||||
// URL preview on input
|
||||
const urlInput = document.querySelector('#link-form input[name="url"]');
|
||||
if (urlInput) {
|
||||
let debounceTimer;
|
||||
urlInput.addEventListener('input', (e) => {
|
||||
clearTimeout(debounceTimer);
|
||||
debounceTimer = setTimeout(() => fetchPreview(e.target.value), 500);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Fetch URL preview
|
||||
async function fetchPreview(url) {
|
||||
const preview = document.getElementById('link-preview');
|
||||
if (!url) {
|
||||
preview.classList.remove('active');
|
||||
preview.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/preview', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ url })
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const data = await res.json();
|
||||
preview.innerHTML = `<div class="preview-error">${data.error || 'Failed to fetch preview'}</div>`;
|
||||
preview.classList.add('active');
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
preview.dataset.preview = JSON.stringify(data);
|
||||
|
||||
let html = '';
|
||||
if (data.imageUrl) {
|
||||
html += `<img src="${escapeHtml(data.imageUrl)}" alt="Preview">`;
|
||||
}
|
||||
if (data.title) {
|
||||
html += `<div class="preview-title">${escapeHtml(data.title)}</div>`;
|
||||
}
|
||||
if (data.description) {
|
||||
html += `<div class="preview-description">${escapeHtml(data.description)}</div>`;
|
||||
}
|
||||
if (data.isEmbed) {
|
||||
html += `<div class="preview-badge">${escapeHtml(data.provider.toUpperCase())} VIDEO</div>`;
|
||||
}
|
||||
|
||||
preview.innerHTML = html || '<div>No preview available</div>';
|
||||
preview.classList.add('active');
|
||||
|
||||
// Auto-fill title if empty
|
||||
const titleInput = document.querySelector('#link-form input[name="title"]');
|
||||
if (titleInput && !titleInput.value && data.title) {
|
||||
titleInput.value = data.title;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Preview error:', err);
|
||||
preview.innerHTML = '<div class="preview-error">Failed to fetch preview</div>';
|
||||
preview.classList.add('active');
|
||||
}
|
||||
}
|
||||
|
||||
// Submit link form
|
||||
async function submitLink(event) {
|
||||
event.preventDefault();
|
||||
const form = event.target;
|
||||
const url = form.url.value;
|
||||
const tags = form.tags.value ? form.tags.value.split(',').map(t => t.trim()).filter(Boolean) : [];
|
||||
|
||||
// Get preview data
|
||||
const preview = document.getElementById('link-preview');
|
||||
const previewData = preview.dataset.preview ? JSON.parse(preview.dataset.preview) : {};
|
||||
|
||||
// Use form values, falling back to preview data
|
||||
const title = form.title.value || previewData.title || null;
|
||||
const description = form.description.value || previewData.description || null;
|
||||
|
||||
try {
|
||||
const body = {
|
||||
url,
|
||||
title,
|
||||
description,
|
||||
tags,
|
||||
imageUrl: previewData.imageUrl || null,
|
||||
};
|
||||
|
||||
if (previewData.isEmbed) {
|
||||
body.provider = previewData.provider;
|
||||
body.videoId = previewData.videoId;
|
||||
body.embedHtml = previewData.embedHtml;
|
||||
}
|
||||
|
||||
const res = await fetch('/api/items/from-link', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
location.reload();
|
||||
} else {
|
||||
const data = await res.json();
|
||||
alert(data.error || 'Failed to add item');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Submit error:', err);
|
||||
alert('Failed to add item');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Submit upload form
|
||||
async function submitUpload(event) {
|
||||
event.preventDefault();
|
||||
const form = event.target;
|
||||
const formData = new FormData(form);
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/items/upload', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
location.reload();
|
||||
} else {
|
||||
const data = await res.json();
|
||||
alert(data.error || 'Failed to upload');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Upload error:', err);
|
||||
alert('Failed to upload');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Submit quote form
|
||||
async function submitQuote(event) {
|
||||
event.preventDefault();
|
||||
const form = event.target;
|
||||
const text = form.text.value;
|
||||
const source = form.source.value || null;
|
||||
const sourceUrl = form.sourceUrl.value || null;
|
||||
const tags = form.tags.value ? form.tags.value.split(',').map(t => t.trim()).filter(Boolean) : [];
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/items/quote', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ text, source, sourceUrl, tags })
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
location.reload();
|
||||
} else {
|
||||
const data = await res.json();
|
||||
alert(data.error || 'Failed to add quote');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Submit error:', err);
|
||||
alert('Failed to add quote');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Edit item
|
||||
function editItem(id) {
|
||||
showEditModal();
|
||||
}
|
||||
|
||||
// Submit edit form
|
||||
async function submitEdit(event) {
|
||||
event.preventDefault();
|
||||
const form = event.target;
|
||||
const id = form.id.value;
|
||||
const title = form.title.value || null;
|
||||
const description = form.description.value || null;
|
||||
const linkUrl = form.linkUrl.value || null;
|
||||
const tags = form.tags.value ? form.tags.value.split(',').map(t => t.trim()).filter(Boolean) : [];
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/items/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ title, description, linkUrl, tags })
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
location.reload();
|
||||
} else {
|
||||
const data = await res.json();
|
||||
alert(data.error || 'Failed to update');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Update error:', err);
|
||||
alert('Failed to update');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Refresh metadata
|
||||
async function refreshMetadata(id) {
|
||||
try {
|
||||
// Fetch current item data
|
||||
const itemRes = await fetch(`/api/items/${id}`);
|
||||
if (!itemRes.ok) {
|
||||
alert('Failed to fetch item');
|
||||
return;
|
||||
}
|
||||
const item = await itemRes.json();
|
||||
|
||||
if (!item.linkUrl) {
|
||||
alert('Item has no link URL');
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch fresh metadata
|
||||
const previewRes = await fetch('/api/preview', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ url: item.linkUrl })
|
||||
});
|
||||
if (!previewRes.ok) {
|
||||
const data = await previewRes.json();
|
||||
alert(data.error || 'Failed to fetch metadata');
|
||||
return;
|
||||
}
|
||||
const preview = await previewRes.json();
|
||||
|
||||
// Check if user has made manual edits
|
||||
const titleChanged = item.title && preview.title && item.title !== preview.title;
|
||||
const descChanged = item.description && preview.description && item.description !== preview.description;
|
||||
const imageChanged = item.thumbnailSourceUrl && preview.imageUrl && item.thumbnailSourceUrl !== preview.imageUrl;
|
||||
|
||||
if (titleChanged || descChanged || imageChanged) {
|
||||
let msg = 'This will overwrite your changes:\n';
|
||||
if (titleChanged) msg += `\nTitle: "${item.title}" → "${preview.title}"`;
|
||||
if (descChanged) msg += `\nDescription will be replaced`;
|
||||
if (imageChanged) msg += `\nImage will be replaced`;
|
||||
msg += '\n\nContinue?';
|
||||
|
||||
if (!confirm(msg)) return;
|
||||
}
|
||||
|
||||
// Proceed with refresh
|
||||
const res = await fetch(`/api/items/${id}/refresh`, { method: 'POST' });
|
||||
|
||||
if (res.ok) {
|
||||
location.reload();
|
||||
} else {
|
||||
const data = await res.json();
|
||||
alert(data.error || 'Failed to refresh');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Refresh error:', err);
|
||||
alert('Failed to refresh');
|
||||
}
|
||||
}
|
||||
|
||||
// Replace media
|
||||
async function submitReplaceMedia(event, id) {
|
||||
event.preventDefault();
|
||||
const form = event.target;
|
||||
const formData = new FormData(form);
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/items/${id}/media`, {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
location.reload();
|
||||
} else {
|
||||
const data = await res.json();
|
||||
alert(data.error || 'Failed to replace media');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Replace media error:', err);
|
||||
alert('Failed to replace media');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Delete item
|
||||
async function deleteItem(id) {
|
||||
if (!confirm('Delete this item?')) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/items/${id}`, { method: 'DELETE' });
|
||||
|
||||
if (res.ok) {
|
||||
location.href = '/';
|
||||
} else {
|
||||
const data = await res.json();
|
||||
alert(data.error || 'Failed to delete');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Delete error:', err);
|
||||
alert('Failed to delete');
|
||||
}
|
||||
}
|
||||
|
||||
// Utility
|
||||
function escapeHtml(str) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = str;
|
||||
return div.innerHTML;
|
||||
}
|
||||
43
internal/static/static.go
Normal file
43
internal/static/static.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package static
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"embed"
|
||||
"encoding/hex"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
//go:embed css/* js/* fonts/*
|
||||
var staticFS embed.FS
|
||||
|
||||
// Version is set via -ldflags in production
|
||||
var Version string
|
||||
|
||||
func init() {
|
||||
if Version == "" {
|
||||
h := sha256.Sum256([]byte(time.Now().String()))
|
||||
Version = hex.EncodeToString(h[:4])
|
||||
}
|
||||
}
|
||||
|
||||
func VersionedPath(path string) string {
|
||||
return "/static/" + Version + "/" + path
|
||||
}
|
||||
|
||||
func Handler() http.Handler {
|
||||
fileServer := http.FileServer(http.FS(staticFS))
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// Strip version prefix: /static/{version}/file.css -> /file.css
|
||||
path := r.URL.Path
|
||||
path = strings.TrimPrefix(path, "/static/")
|
||||
if idx := strings.Index(path, "/"); idx != -1 {
|
||||
path = path[idx:]
|
||||
}
|
||||
r.URL.Path = path
|
||||
|
||||
w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
|
||||
fileServer.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue