mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-07-09 14:31:47 +08:00
✨ Feature: pictures uploaded using webdav and local path can be previewed in gallery now
ISSUES CLOSED: #64
This commit is contained in:
32
src/main/fileServer/index.ts
Normal file
32
src/main/fileServer/index.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import http from 'http'
|
||||
import fs from 'fs-extra'
|
||||
import path from 'path'
|
||||
import picgo from '@core/picgo'
|
||||
import logger from '../apis/core/picgo/logger'
|
||||
|
||||
export const imgFilePath = path.join(picgo.baseDir, 'imgTemp')
|
||||
fs.ensureDirSync(imgFilePath)
|
||||
|
||||
const serverPort = 36699
|
||||
|
||||
export function startFileServer () {
|
||||
const server = http.createServer((req, res) => {
|
||||
const requestPath = req.url?.split('?')[0]
|
||||
const filePath = path.join(imgFilePath, requestPath!)
|
||||
|
||||
fs.readFile(filePath, (err, data) => {
|
||||
if (err) {
|
||||
res.writeHead(404)
|
||||
res.end('404 Not Found')
|
||||
} else {
|
||||
res.end(data)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
server.listen(serverPort, () => {
|
||||
logger.info(`File server is running, http://localhost:${serverPort}`)
|
||||
}).on('error', (err) => {
|
||||
logger.error(err)
|
||||
})
|
||||
}
|
||||
@@ -47,6 +47,7 @@ import clipboardPoll from '../utils/clipboardPoll'
|
||||
import path from 'path'
|
||||
import { CLIPBOARD_IMAGE_FOLDER } from '~/universal/utils/static'
|
||||
import fs from 'fs-extra'
|
||||
import { startFileServer } from '../fileServer'
|
||||
const isDevelopment = process.env.NODE_ENV !== 'production'
|
||||
|
||||
const handleStartUpFiles = (argv: string[], cwd: string) => {
|
||||
@@ -158,6 +159,7 @@ class LifeCycle {
|
||||
shortKeyHandler.init()
|
||||
})
|
||||
server.startup()
|
||||
startFileServer()
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
handleStartUpFiles(process.argv, process.cwd())
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@
|
||||
@click="zoomImage(index)"
|
||||
>
|
||||
<img
|
||||
v-lazy="item.imgUrl"
|
||||
v-lazy="item.galleryPath || item.imgUrl"
|
||||
class="gallery-list__item-img"
|
||||
>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user