Introduce initial project scaffold: Express webhook server (server.js) for Immich uploads, DB pool (modules/database.js) using pg, immich repository (repositories/immichRepo.js) with get/update functions, image processing via sharp (modules/image_processor.js), a small execution helper (modules/execution_helper.js), and package.json + package-lock. Server validates a bearer token, filters non-image assets, waits briefly, compresses the image and updates DB path. Requires env vars: DB_HOST, DB_USER, DB_PORT, DB_NAME, DB_PASS, PASS_CODE, IMMICH_DATA_PATH, IMG_COMPRESSION_OUTPUT_FORMAT, IMG_COMPRESSION_OUTPUT_QUALITY, PORT.
31 lines
865 B
JavaScript
31 lines
865 B
JavaScript
import { pool } from "../modules/database.js"
|
|
|
|
async function getMediaInDatabase(mediaId) {
|
|
try {
|
|
const query = "SELECT * FROM asset WHERE id = $1"
|
|
const values = [mediaId]
|
|
const response = await pool.query(query, values)
|
|
return response.rows
|
|
} catch (error) {
|
|
console.error("Erreur dans getMediaInDatabase:", error)
|
|
throw error
|
|
}
|
|
}
|
|
|
|
async function updateMediaPathInDatabase(mediaId, newPath) {
|
|
try {
|
|
const query = "UPDATE asset SET \"originalPath\" = $1 WHERE id = $2"
|
|
const values = [newPath, mediaId]
|
|
const response = await pool.query(query, values)
|
|
return response.rows
|
|
} catch (error) {
|
|
console.error("Erreur dans updateMediaPathInDatabase:", error)
|
|
throw error
|
|
}
|
|
}
|
|
|
|
|
|
export default {
|
|
getMediaInDatabase,
|
|
updateMediaPathInDatabase
|
|
} |