mirror of
https://github.com/ergosteur/instaarchive-viewer.git
synced 2026-07-04 11:07:15 -04:00
fix: improve Docker archive discovery and switch to compiled server
This commit is contained in:
@@ -7,7 +7,7 @@ WORKDIR /app
|
|||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
|
|
||||||
# Copy source and build frontend
|
# Copy source and build (frontend and server)
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
@@ -27,12 +27,12 @@ RUN npm ci --omit=dev
|
|||||||
|
|
||||||
# Copy built assets and server
|
# Copy built assets and server
|
||||||
COPY --from=build /app/dist ./dist
|
COPY --from=build /app/dist ./dist
|
||||||
COPY --from=build /app/server.ts ./
|
COPY --from=build /app/dist-server/server.js ./server.js
|
||||||
|
|
||||||
# Ensure archives directory exists
|
# Ensure archives directory exists
|
||||||
RUN mkdir -p /archives
|
RUN mkdir -p /archives
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Start server using tsx
|
# Start server
|
||||||
CMD ["npx", "tsx", "server.ts"]
|
CMD ["node", "server.js"]
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "react-example",
|
"name": "react-example",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.1.0",
|
"version": "1.1.1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite --port=3000 --host=0.0.0.0",
|
"dev": "vite --port=3000 --host=0.0.0.0",
|
||||||
"build": "vite build",
|
"build": "vite build && npm run build:server",
|
||||||
|
"build:server": "tsc server.ts --esModuleInterop --module ESNext --target ES2022 --moduleResolution bundler --outDir dist-server",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"server": "tsx server.ts",
|
"server": "tsx server.ts",
|
||||||
"clean": "rm -rf dist",
|
"clean": "rm -rf dist",
|
||||||
|
|||||||
24
server.ts
24
server.ts
@@ -11,12 +11,18 @@ const __dirname = path.dirname(__filename);
|
|||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = process.env.PORT || 3001;
|
const PORT = process.env.PORT || 3001;
|
||||||
const ARCHIVES_DIR = process.env.ARCHIVES_DIR || path.join(__dirname, '_sample-archives');
|
const ARCHIVES_DIR = path.resolve(process.env.ARCHIVES_DIR || path.join(__dirname, '_sample-archives'));
|
||||||
|
|
||||||
|
console.log(`[Server] Initializing...`);
|
||||||
|
console.log(`[Server] Environment ARCHIVES_DIR: ${process.env.ARCHIVES_DIR}`);
|
||||||
|
console.log(`[Server] Resolved ARCHIVES_DIR: ${ARCHIVES_DIR}`);
|
||||||
|
|
||||||
// Ensure archives directory exists
|
// Ensure archives directory exists
|
||||||
if (!fs.existsSync(ARCHIVES_DIR)) {
|
if (!fs.existsSync(ARCHIVES_DIR)) {
|
||||||
console.warn(`Warning: Archives directory not found at ${ARCHIVES_DIR}. Creating it...`);
|
console.warn(`[Server] Warning: Archives directory not found at ${ARCHIVES_DIR}. Creating it...`);
|
||||||
fs.mkdirSync(ARCHIVES_DIR, { recursive: true });
|
fs.mkdirSync(ARCHIVES_DIR, { recursive: true });
|
||||||
|
} else {
|
||||||
|
console.log(`[Server] Archives directory exists.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
@@ -24,13 +30,21 @@ app.use(express.json());
|
|||||||
// API: List archives (subdirectories in ARCHIVES_DIR)
|
// API: List archives (subdirectories in ARCHIVES_DIR)
|
||||||
app.get('/api/archives', (req, res) => {
|
app.get('/api/archives', (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
console.log(`[API] Listing archives from ${ARCHIVES_DIR}...`);
|
||||||
const items = fs.readdirSync(ARCHIVES_DIR, { withFileTypes: true });
|
const items = fs.readdirSync(ARCHIVES_DIR, { withFileTypes: true });
|
||||||
|
console.log(`[API] Found ${items.length} total items in archives directory.`);
|
||||||
|
|
||||||
const archives = items
|
const archives = items
|
||||||
.filter(item => item.isDirectory())
|
.filter(item => {
|
||||||
|
const isDir = item.isDirectory();
|
||||||
|
if (!isDir) console.log(`[API] Skipping non-directory: ${item.name}`);
|
||||||
|
return isDir;
|
||||||
|
})
|
||||||
.map(item => {
|
.map(item => {
|
||||||
// Try to find a profile pic or first image for the thumbnail
|
// Try to find a profile pic or first image for the thumbnail
|
||||||
const archivePath = path.join(ARCHIVES_DIR, item.name);
|
const archivePath = path.join(ARCHIVES_DIR, item.name);
|
||||||
const files = fs.readdirSync(archivePath);
|
const files = fs.readdirSync(archivePath);
|
||||||
|
console.log(`[API] Found archive: ${item.name} (${files.length} files)`);
|
||||||
|
|
||||||
let thumbnail = '';
|
let thumbnail = '';
|
||||||
const profilePic = files.find(f => f.toLowerCase().includes('_profile_pic.jpg') || f.toLowerCase() === `${item.name.toLowerCase()}.jpg`);
|
const profilePic = files.find(f => f.toLowerCase().includes('_profile_pic.jpg') || f.toLowerCase() === `${item.name.toLowerCase()}.jpg`);
|
||||||
@@ -48,9 +62,11 @@ app.get('/api/archives', (req, res) => {
|
|||||||
fileCount: files.length
|
fileCount: files.length
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(`[API] Returning ${archives.length} validated archives.`);
|
||||||
res.json(archives);
|
res.json(archives);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error listing archives:', err);
|
console.error('[API] Error listing archives:', err);
|
||||||
res.status(500).json({ error: 'Failed to list archives' });
|
res.status(500).json({ error: 'Failed to list archives' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user