@xiguanpm/inkos-web 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>InkOS Web - 小说写作管理系统</title>
8
+ <script type="module" crossorigin src="/assets/index-ReWNfPBN.js"></script>
9
+ <link rel="stylesheet" crossorigin href="/assets/index-Qa7RFOD5.css">
10
+ </head>
11
+ <body>
12
+ <div id="root"></div>
13
+ </body>
14
+ </html>
@@ -0,0 +1,104 @@
1
+ const express = require('express');
2
+ const cors = require('cors');
3
+ const bodyParser = require('body-parser');
4
+ const multer = require('multer');
5
+ const path = require('path');
6
+ const fs = require('fs');
7
+
8
+ const app = express();
9
+ const port = process.env.PORT || 8081;
10
+
11
+ app.use(cors({
12
+ origin: process.env.CORS_ORIGIN || 'http://localhost:8081',
13
+ credentials: true,
14
+ }));
15
+
16
+ const distPath = path.join(__dirname, '..', 'dist');
17
+ app.use(express.static(distPath));
18
+
19
+ app.use(bodyParser.json({ limit: '10mb' }));
20
+ app.use(bodyParser.urlencoded({ extended: true, limit: '10mb' }));
21
+
22
+ const uploadDir = process.env.UPLOAD_DIR || path.join(__dirname, 'uploads');
23
+ if (!fs.existsSync(uploadDir)) {
24
+ fs.mkdirSync(uploadDir, { recursive: true });
25
+ }
26
+
27
+ const storage = multer.diskStorage({
28
+ destination: (req, file, cb) => {
29
+ cb(null, uploadDir);
30
+ },
31
+ filename: (req, file, cb) => {
32
+ const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1e9);
33
+ const ext = path.extname(file.originalname);
34
+ cb(null, uniqueSuffix + ext);
35
+ },
36
+ });
37
+
38
+ const upload = multer({
39
+ storage: storage,
40
+ limits: {
41
+ fileSize: parseInt(process.env.UPLOAD_MAX_SIZE) || 10 * 1024 * 1024,
42
+ },
43
+ });
44
+
45
+ const inkosRoutes = require('./routes/inkos');
46
+ app.use('/api', inkosRoutes);
47
+
48
+ app.post('/api/upload', upload.single('file'), (req, res) => {
49
+ if (!req.file) {
50
+ return res.status(400).json({ success: false, error: 'No file uploaded' });
51
+ }
52
+ res.json({
53
+ success: true,
54
+ data: {
55
+ filename: req.file.filename,
56
+ originalname: req.file.originalname,
57
+ path: req.file.path,
58
+ size: req.file.size,
59
+ },
60
+ });
61
+ });
62
+
63
+ app.get('/api/health', (req, res) => {
64
+ res.json({ status: 'ok', timestamp: new Date().toISOString() });
65
+ });
66
+
67
+ app.get('/api/upload/:filename', (req, res) => {
68
+ try {
69
+ const { filename } = req.params;
70
+ const filePath = path.join(uploadDir, filename);
71
+
72
+ if (!fs.existsSync(filePath)) {
73
+ return res.status(404).json({ success: false, error: 'File not found' });
74
+ }
75
+
76
+ const content = fs.readFileSync(filePath, 'utf-8');
77
+ res.json({ success: true, data: { content }, stdout: '' });
78
+ } catch (error) {
79
+ res.status(500).json({ success: false, error: error.message });
80
+ }
81
+ });
82
+
83
+ app.use((err, req, res, next) => {
84
+ console.error('Error:', err);
85
+ res.status(500).json({
86
+ success: false,
87
+ error: err.message || 'Internal server error',
88
+ });
89
+ });
90
+
91
+ app.get('*', (req, res) => {
92
+ const indexPath = path.join(distPath, 'index.html');
93
+ if (fs.existsSync(indexPath)) {
94
+ res.sendFile(indexPath);
95
+ } else {
96
+ res.status(404).send('Frontend not found');
97
+ }
98
+ });
99
+
100
+ app.listen(port, () => {
101
+ console.log(`InkOS Web Server running on http://localhost:${port}`);
102
+ console.log(`API endpoint: http://localhost:${port}/api`);
103
+ console.log(`Upload directory: ${uploadDir}`);
104
+ });