This commit is contained in:
lesion 2022-08-18 09:44:51 +02:00
parent 6a9bb59a7e
commit fa55f75c7e
9 changed files with 42 additions and 52 deletions

4
components.d.ts vendored
View file

@ -8,12 +8,8 @@ export {}
declare module '@vue/runtime-core' { declare module '@vue/runtime-core' {
export interface GlobalComponents { export interface GlobalComponents {
'IconIc:baselineAdd': typeof import('~icons/ic/baseline-add')['default'] 'IconIc:baselineAdd': typeof import('~icons/ic/baseline-add')['default']
'IconIc:baselineArrow': typeof import('~icons/ic/baseline-arrow')['default']
'IconIc:baselineArrowLeft': typeof import('~icons/ic/baseline-arrow-left')['default']
'IconIc:baselineChevronLeft': typeof import('~icons/ic/baseline-chevron-left')['default'] 'IconIc:baselineChevronLeft': typeof import('~icons/ic/baseline-chevron-left')['default']
'IconIc:baselineChevronPrev': typeof import('~icons/ic/baseline-chevron-prev')['default']
'IconIc:baselineChevronRight': typeof import('~icons/ic/baseline-chevron-right')['default'] 'IconIc:baselineChevronRight': typeof import('~icons/ic/baseline-chevron-right')['default']
'IconIc:baselineNext': typeof import('~icons/ic/baseline-next')['default']
RouterLink: typeof import('vue-router')['RouterLink'] RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView'] RouterView: typeof import('vue-router')['RouterView']
} }

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="`src/public/${cosetta.images[0]}`" alt="Mountain"> <img class="object-cover w-full h-48" :src="`/imgs/${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

@ -1,22 +1,24 @@
import { defineNuxtConfig } from 'nuxt' import { defineNuxtConfig } from 'nuxt'
import UnpluginComponentsVite from 'unplugin-vue-components/vite' import UnpluginComponentsVite from 'unplugin-vue-components/vite'
import IconsResolver from 'unplugin-icons/resolver' import IconsResolver from 'unplugin-icons/resolver'
import serveStatic from 'serve-static'
// https://v3.nuxtjs.org/api/configuration/nuxt.config // https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({ export default defineNuxtConfig({
ssr: true, ssr: true,
buildModules: ['@nuxtjs/tailwindcss', 'unplugin-icons/nuxt', '@nuxtjs/svg'], buildModules: ['@nuxtjs/tailwindcss', 'unplugin-icons/nuxt', '@nuxtjs/svg'],
serverMiddleware: [
{ path: '/imgs', handler: serveStatic(__dirname + '/imgs') }
],
vite: { vite: {
plugins: [ plugins: [
UnpluginComponentsVite({ UnpluginComponentsVite({
dts: true, dts: true,
resolvers: [ resolvers: [
IconsResolver({ IconsResolver({ prefix: 'Icon' }),
prefix: 'Icon', ],
}), }),
],
}),
], ],
}, },
}) })

View file

@ -7,10 +7,10 @@
"preview": "nuxt preview" "preview": "nuxt preview"
}, },
"devDependencies": { "devDependencies": {
"@iconify/json": "^2.1.91", "@iconify/json": "^2.1.94",
"@nuxtjs/svg": "^0.4.0", "@nuxtjs/svg": "^0.4.0",
"@nuxtjs/tailwindcss": "^5.3.1", "@nuxtjs/tailwindcss": "^5.3.2",
"daisyui": "^2.22.0", "daisyui": "^2.24.0",
"nuxt": "3.0.0-rc.6", "nuxt": "3.0.0-rc.6",
"unplugin-icons": "^0.14.8", "unplugin-icons": "^0.14.8",
"unplugin-vue-components": "^0.22.4" "unplugin-vue-components": "^0.22.4"
@ -19,6 +19,7 @@
"@tailwindcss/line-clamp": "^0.4.0", "@tailwindcss/line-clamp": "^0.4.0",
"better-sqlite3": "^7.6.2", "better-sqlite3": "^7.6.2",
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",
"serve-static": "^1.15.0",
"uuid": "^8.3.2" "uuid": "^8.3.2"
} }
} }

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="`/src/public/${cosetta.images[0]}`" /> <img v-if='cosetta.images' :src="`/imgs/${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

@ -9,7 +9,7 @@ export default defineEventHandler(async (event) => {
const body = await useBody(event) const body = await useBody(event)
body.imgs = [event.req.file?.filename] body.imgs = [event.req.file?.filename]
add(body) add(body)
return sendRedirect(event, 'http://localhost:3000') return sendRedirect(event, '/')
} catch (e) { } catch (e) {
return { success: false, reason: e.message } return { success: false, reason: e.message }
} }

View file

@ -1,5 +1,6 @@
import Database from 'better-sqlite3' import Database from 'better-sqlite3'
import { v4 } from 'uuid' import { v4 } from 'uuid'
const db = new Database('./cosette.db') const db = new Database('./cosette.db')

View file

@ -1,10 +1,11 @@
import multer from 'multer'; import multer from 'multer'
import type { Options } from 'multer'; import type { Options } from 'multer'
import fs from 'fs'; import fs from 'fs'
import { v4 } from 'uuid'; import { v4 } from 'uuid'
import path from 'path'
export const uploadService = () => { export const uploadService = () => {
let folderPath = process.env.NODE_ENV == 'development' ? './src/public/' : './public/'; let folderPath = './imgs/'
if (!fs.existsSync(folderPath)) { if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath, { recursive: true }) fs.mkdirSync(folderPath, { recursive: true })
} }
@ -18,13 +19,10 @@ export const uploadService = () => {
const { filename }: multer.DiskStorageOptions = { const { filename }: multer.DiskStorageOptions = {
filename: (_req, file, cb) => { filename: (_req, file, cb) => {
const splittedFileName = file.originalname.split('.'); const type = path.extname(file.originalname)
let name = splittedFileName[0]; cb(null, v4() + type)
const type = splittedFileName[1]; }
name += '-' + v4().slice(0, 5) + '.' + type; }
cb(null, name);
},
};
const generateHandler = () => { const generateHandler = () => {
try { try {

View file

@ -293,10 +293,10 @@
resolved "https://registry.yarnpkg.com/@csstools/selector-specificity/-/selector-specificity-2.0.2.tgz#1bfafe4b7ed0f3e4105837e056e0a89b108ebe36" resolved "https://registry.yarnpkg.com/@csstools/selector-specificity/-/selector-specificity-2.0.2.tgz#1bfafe4b7ed0f3e4105837e056e0a89b108ebe36"
integrity sha512-IkpVW/ehM1hWKln4fCA3NzJU8KwD+kIOvPZA4cqxoJHtE21CCzjyp+Kxbu0i5I4tBNOlXPL9mjwnWlL0VEG4Fg== integrity sha512-IkpVW/ehM1hWKln4fCA3NzJU8KwD+kIOvPZA4cqxoJHtE21CCzjyp+Kxbu0i5I4tBNOlXPL9mjwnWlL0VEG4Fg==
"@iconify/json@^2.1.91": "@iconify/json@^2.1.94":
version "2.1.91" version "2.1.94"
resolved "https://registry.yarnpkg.com/@iconify/json/-/json-2.1.91.tgz#d66e9a8e41ebbde74fa4278c31777dbf54393b1f" resolved "https://registry.yarnpkg.com/@iconify/json/-/json-2.1.94.tgz#bb53f535cd05b5cc351350f8d8ad08868c07937d"
integrity sha512-GjvdX5E09r0hjRp6woaR2bUPpziMboqk3Cdb1cVi4bZTQT4hdHOBJ8IxV9LNgBTfeNgbxWIf1w+IhFG1xawvrg== integrity sha512-/AFIlLMrnuZpWubJgmt1//iEhg6ZnDPMs4J3TvOZLcN2PYQFDnILBe2r8c3wZ3wd/OsDN5LSHJv0l9HJTfpEFw==
dependencies: dependencies:
"@iconify/types" "*" "@iconify/types" "*"
pathe "^0.3.0" pathe "^0.3.0"
@ -587,14 +587,13 @@
url-loader "^4.1.0" url-loader "^4.1.0"
vue-svg-loader "^0.16.0" vue-svg-loader "^0.16.0"
"@nuxtjs/tailwindcss@^5.3.1": "@nuxtjs/tailwindcss@^5.3.2":
version "5.3.1" version "5.3.2"
resolved "https://registry.yarnpkg.com/@nuxtjs/tailwindcss/-/tailwindcss-5.3.1.tgz#5c90ba3df4782653f0c625ea7eb7e898fa2844c1" resolved "https://registry.yarnpkg.com/@nuxtjs/tailwindcss/-/tailwindcss-5.3.2.tgz#1c9cb3ac82a5ded7e931a158b90ec5ef566e7bfb"
integrity sha512-NrnYUA65DWG9cB6wLdK7NMhaDIIAbqxmMueGIvqy8xuTfHGNvtjFZQY2ywu60N70cjIYqYnbyJURj+PQoNN9Ew== integrity sha512-otxYJ1uLf5O3xKUpdw8kZkyaAPKj7RRqygxBmjs6fWrLCGM1lg3kda610GdWZY4O9lDjgqtQfjK+13ByhYgsbg==
dependencies: dependencies:
"@nuxt/kit" "^3.0.0-rc.5" "@nuxt/kit" "^3.0.0-rc.5"
"@nuxt/postcss8" "^1.1.3" "@nuxt/postcss8" "^1.1.3"
"@types/tailwindcss" "^3.0.11"
autoprefixer "^10.4.7" autoprefixer "^10.4.7"
chalk "^5.0.1" chalk "^5.0.1"
clear-module "^4.1.2" clear-module "^4.1.2"
@ -746,13 +745,6 @@
dependencies: dependencies:
"@types/node" "*" "@types/node" "*"
"@types/tailwindcss@^3.0.11":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@types/tailwindcss/-/tailwindcss-3.1.0.tgz#1185e4b3437c6e0f19d6cc8cd42738a94fd7b64f"
integrity sha512-JxPzrm609hzvF4nmOI3StLjbBEP3WWQxDDJESqR1nh94h7gyyy3XSl0hn5RBMJ9mPudlLjtaXs5YEBtLw7CnPA==
dependencies:
tailwindcss "*"
"@types/tough-cookie@*": "@types/tough-cookie@*":
version "4.0.2" version "4.0.2"
resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.2.tgz#6286b4c7228d58ab7866d19716f3696e03a09397" resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.2.tgz#6286b4c7228d58ab7866d19716f3696e03a09397"
@ -1899,10 +1891,10 @@ cuint@^0.2.2:
resolved "https://registry.yarnpkg.com/cuint/-/cuint-0.2.2.tgz#408086d409550c2631155619e9fa7bcadc3b991b" resolved "https://registry.yarnpkg.com/cuint/-/cuint-0.2.2.tgz#408086d409550c2631155619e9fa7bcadc3b991b"
integrity sha512-d4ZVpCW31eWwCMe1YT3ur7mUDnTXbgwyzaL320DrcRT45rfjYxkt5QWLrmOJ+/UEAI2+fQgKe/fCjR8l4TpRgw== integrity sha512-d4ZVpCW31eWwCMe1YT3ur7mUDnTXbgwyzaL320DrcRT45rfjYxkt5QWLrmOJ+/UEAI2+fQgKe/fCjR8l4TpRgw==
daisyui@^2.22.0: daisyui@^2.24.0:
version "2.22.0" version "2.24.0"
resolved "https://registry.yarnpkg.com/daisyui/-/daisyui-2.22.0.tgz#00ea4948fb886ad5242bd6bd3d1a229a8f28d932" resolved "https://registry.yarnpkg.com/daisyui/-/daisyui-2.24.0.tgz#7eacfc943815979227cf50b98f7df622c2814118"
integrity sha512-H08aQP+Mfl2fQOmyaxd1NP54gQbr2xRUj2MmFFvfJ5EDGbthVBICDMNFKyia/zBfR58G8eTJo3CmydglM81/7Q== integrity sha512-Fdu/4LCdTfWLWAbCuPxvnaRotEfJ+hVPgZ2kv/aUk9RZ00Yk8fGdJtIf0kXJ3IgUKOr8rCXUpfQY6DQU9usPCQ==
dependencies: dependencies:
color "^4.2" color "^4.2"
css-selector-tokenizer "^0.8.0" css-selector-tokenizer "^0.8.0"
@ -5968,7 +5960,7 @@ tailwind-config-viewer@^1.7.1:
portfinder "^1.0.26" portfinder "^1.0.26"
replace-in-file "^6.1.0" replace-in-file "^6.1.0"
tailwindcss@*, tailwindcss@^3, tailwindcss@^3.1.6: tailwindcss@^3, tailwindcss@^3.1.6:
version "3.1.6" version "3.1.6"
resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-3.1.6.tgz#bcb719357776c39e6376a8d84e9834b2b19a49f1" resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-3.1.6.tgz#bcb719357776c39e6376a8d84e9834b2b19a49f1"
integrity sha512-7skAOY56erZAFQssT1xkpk+kWt2NrO45kORlxFPXUt3CiGsVPhH1smuH5XoDH6sGPXLyBv+zgCKA2HWBsgCytg== integrity sha512-7skAOY56erZAFQssT1xkpk+kWt2NrO45kORlxFPXUt3CiGsVPhH1smuH5XoDH6sGPXLyBv+zgCKA2HWBsgCytg==