-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
339 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ logs/* | |
*.log | ||
*.local | ||
temp/ | ||
debug/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const env = process.env; | ||
module.exports = { | ||
ADMIN_WHITELIST: env.ADMIN_WHITELIST.split(','), | ||
SESSION_KEYS: env.SESSION_KEYS, | ||
PORT: env.PORT, | ||
SERVICE_NAME: 'rosendofun.service', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { getStaticFile } = require('../common/utils'); | ||
const logger = require('../common/logger'); | ||
const utils = require('../common/utils'); | ||
const JSONStream = require('../common/jsonStream'); | ||
const { rootDir } = require('../common/constant'); | ||
const { assert } = require('console'); | ||
|
||
module.exports = { | ||
resCode(ctx, next) { | ||
let { code, type } = ctx.params; | ||
code = ~~code; | ||
assert(typeof code === 'number'); | ||
|
||
ctx.status = code; | ||
switch (code) { | ||
case 401: | ||
if (type == 'digest') { | ||
ctx.set( | ||
'WWW-Authenticate', | ||
'Digest realm="Restricted Access", algorithm="MD5", qop="auth", nonce="' + | ||
Math.random().toString(36).substring(7) + | ||
'"' | ||
); | ||
} else if (type == 'bearer') { | ||
ctx.set('WWW-Authenticate', 'Bearer realm="Restricted Access"'); | ||
} else { | ||
ctx.set('WWW-Authenticate', 'Basic realm="Restricted Access"'); | ||
} | ||
ctx.body = 'Unauthorized'; | ||
break; | ||
|
||
default: | ||
ctx.body = {}; | ||
break; | ||
} | ||
}, | ||
async resStream(ctx, next) { | ||
const { streamType } = ctx.params; | ||
const jsonType = streamType == 'json'; | ||
const data = jsonType | ||
? fs.readFileSync(path.resolve('static', 'index.json.text')).toString().split(/\n/) | ||
: Array.from({ length: 3 }).map((val, i) => `This is chunk ${i + 1}`); | ||
|
||
ctx.res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
|
||
for (let index = 0; index < data.length; index++) { | ||
const chunk = data[index]; | ||
ctx.res.write(chunk); | ||
index != data.length - 1 && (await utils.waitForSeconds(3e3)); | ||
} | ||
// Optionally, you can end the response after writing all data | ||
ctx.res.end(); | ||
}, | ||
async resContentType(ctx, next) { | ||
const { contentType } = ctx.params; | ||
switch (contentType) { | ||
case 'html': | ||
ctx.type = 'text/html'; | ||
ctx.body = getStaticFile('index.html'); | ||
break; | ||
case 'text': | ||
ctx.type = 'text/plain'; | ||
ctx.body = getStaticFile('index.txt'); | ||
break; | ||
case 'img': | ||
ctx.type = 'image/png'; | ||
// ctx.body = fs.readFileSync(path.resolve('static', 'index.png')); | ||
// ctx.body = fs.readFileSync(path.resolve('static', 'index.png')).toString('base64'); | ||
ctx.body = getStaticFile('index.png'); | ||
break; | ||
case 'video': | ||
ctx.type = 'video/mp4'; | ||
ctx.body = getStaticFile('index.mp4'); | ||
break; | ||
case 'css': | ||
ctx.type = 'text/css'; | ||
ctx.body = getStaticFile('index.css'); | ||
break; | ||
case 'xml': | ||
ctx.type = 'application/xml'; | ||
ctx.body = getStaticFile('index.xml'); | ||
break; | ||
case 'js': | ||
ctx.type = 'application/javascript'; | ||
ctx.body = getStaticFile('index.js'); | ||
break; | ||
case 'file': | ||
const fileName = 'index.txt'; | ||
ctx.set('Content-Disposition', `attachment; filename="${fileName}"`); | ||
ctx.type = 'application/octet-stream'; | ||
ctx.body = getStaticFile(fileName); | ||
break; | ||
|
||
case 'json': | ||
default: | ||
ctx.type = 'application/json'; | ||
// WARNNING json must be write one-time | ||
// ctx.body = getStaticFile('index.json'); | ||
ctx.body = JSON.parse(fs.readFileSync(path.resolve(rootDir, 'static/index.json')).toString()); | ||
break; | ||
} | ||
await next(); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const http = require('../middleware/http'); | ||
|
||
const prefix = '/http'; | ||
module.exports = router => { | ||
router | ||
.get(`${prefix}/contentType/:contentType`, http.resContentType) | ||
.get(`${prefix}/res/stream/:streamType`, http.resStream) | ||
.get(`${prefix}/code/:code/:type?`, http.resCode); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const user = require('../middleware/user'); | ||
|
||
const prefix = '/user'; | ||
module.exports = router => { | ||
router | ||
.all('userLogin', `${prefix}/login`, user.userLogin) | ||
.all('userInfo', `${prefix}/info`, user.userInfo) | ||
.all('adminAuth', `${prefix}/auth`, user.adminAuth); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.