This commit is contained in:
lesion 2022-08-22 17:18:45 +02:00
parent 87765ba2c0
commit ddc0b07f7d
4 changed files with 39 additions and 39 deletions

View file

@ -8,7 +8,7 @@ const { cosetta } = defineProps({
</script> </script>
<template> <template>
<div class="rounded overflow-hidden shadow-lg flex flex-col justify-between"> <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"> <div class="px-6 py-4 grow">
<nuxt-link :to="`/c/${cosetta.uuid}`"> <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' /> <h2 class="text-pink-500 card-title hover:underline uppercase mb-2 line-clamp-2" v-text='cosetta.name' />

View file

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

View file

@ -15,7 +15,7 @@ const addComment = async () => {
<section class="bg-white py-8"> <section class="bg-white py-8">
<div class="container mx-auto pt-4 pb-12"> <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' /> <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"> <div class="px-6 pt-4 pb-2">
<span v-for='tag in cosetta.tags' :key='tag' <span v-for='tag in cosetta.tags' :key='tag'

View file

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