Compare commits

...

2 commits

Author SHA1 Message Date
ddc0b07f7d minor 2022-08-22 17:18:45 +02:00
87765ba2c0 startup 2022-08-22 17:18:00 +02:00
7 changed files with 49 additions and 44 deletions

View file

@ -8,7 +8,7 @@ const { cosetta } = defineProps({
</script>
<template>
<div class="rounded overflow-hidden shadow-lg flex flex-col justify-between">
<img class="object-cover w-full h-48" :src="`/imgs/${cosetta.images[0]}`" alt="Mountain">
<img class="object-cover w-full h-48" :src="`/${cosetta.images[0]}`" alt="Mountain">
<div class="px-6 py-4 grow">
<nuxt-link :to="`/c/${cosetta.uuid}`">
<h2 class="text-pink-500 card-title hover:underline uppercase mb-2 line-clamp-2" v-text='cosetta.name' />

View file

@ -6,10 +6,10 @@ import serveStatic from 'serve-static'
// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
ssr: true,
nitro: {
plugins: ['~/server/startup.js'],
},
buildModules: ['@nuxtjs/tailwindcss', 'unplugin-icons/nuxt', '@nuxtjs/svg'],
serverMiddleware: [
{ path: '/imgs', handler: serveStatic(__dirname + '/imgs') }
],
vite: {
plugins: [
UnpluginComponentsVite({

View file

@ -7,11 +7,11 @@
"preview": "nuxt preview"
},
"devDependencies": {
"@iconify/json": "^2.1.94",
"@iconify/json": "^2.1.96",
"@nuxtjs/svg": "^0.4.0",
"@nuxtjs/tailwindcss": "^5.3.2",
"daisyui": "^2.24.0",
"nuxt": "3.0.0-rc.6",
"nuxt": "npm:nuxt3@latest",
"unplugin-icons": "^0.14.8",
"unplugin-vue-components": "^0.22.4"
},

View file

@ -15,7 +15,7 @@ const addComment = async () => {
<section class="bg-white py-8">
<div class="container mx-auto pt-4 pb-12">
<img v-if='cosetta.images' :src="`/imgs/${cosetta.images[0]}`" />
<img v-if='cosetta.images' :src="`/${cosetta.images[0]}`" />
<h2 class="text-pink-500 text-2xl card-title uppercase mb-2 divider" v-text='cosetta.name' />
<div class="px-6 pt-4 pb-2">
<span v-for='tag in cosetta.tags' :key='tag'

View file

@ -4,10 +4,10 @@ import { v4 } from 'uuid'
const db = new Database('./cosette.db')
function load() {
export function load() {
db.pragma('journal_mode = WAL')
db.exec('CREATE TABLE IF NOT EXISTS cosette (uuid TEXT PRIMARY KEY, name TEXT NOT NULL, description TEXT, tags TEXT, images TEXT, updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP)')
db.exec('CREATE INDEX cosette_updated_at_index ON cosette (updatedAt)')
db.exec('CREATE INDEX IF NOT EXISTS cosette_updated_at_index ON cosette (updatedAt)')
db.exec('CREATE TABLE IF NOT EXISTS chan (uuid TEXT PRIMARY KEY, cosetta_uuid REFERENCES cosette(uuid), message TEXT, updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP)')
}
// TODO: da gestire in qualche modo all'avvio

View file

@ -5,42 +5,42 @@ import { v4 } from 'uuid'
import path from 'path'
export const uploadService = () => {
let folderPath = './imgs/'
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath, { recursive: true })
}
const { limits: templateLimits }: Options = {
limits: {
files: 1,
fieldNameSize: 400,
fileSize: 80 * 1024 * 1024,
},
};
let folderPath = './public/'
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath, { recursive: true })
}
const { limits: templateLimits }: Options = {
limits: {
files: 1,
fieldNameSize: 400,
fileSize: 80 * 1024 * 1024,
},
};
const { filename }: multer.DiskStorageOptions = {
filename: (_req, file, cb) => {
const type = path.extname(file.originalname)
cb(null, v4() + type)
}
}
const { filename }: multer.DiskStorageOptions = {
filename: (_req, file, cb) => {
const type = path.extname(file.originalname)
cb(null, v4() + type)
}
}
const generateHandler = () => {
try {
const options: Options = {
limits: {
...templateLimits,
},
storage: multer.diskStorage({
filename,
destination: folderPath
}),
};
const generateHandler = () => {
try {
const options: Options = {
limits: {
...templateLimits,
},
storage: multer.diskStorage({
filename,
destination: folderPath
}),
};
return multer(options).single('imgs');
} catch (e) {
console.error('Upload error', e)
throw e;
}
};
return { generateHandler };
return multer(options).single('imgs');
} catch (e) {
console.error('Upload error', e)
throw e;
}
};
return { generateHandler };
};

5
server/startup.js Normal file
View file

@ -0,0 +1,5 @@
import { load } from '../server/controller'
export default () => {
load()
}