add lidar
parent
ea50afa4ec
commit
d3c68bc333
31
index.js
31
index.js
|
@ -4,6 +4,7 @@ const { S3Client, GetObjectCommand } = require('@aws-sdk/client-s3');
|
||||||
const KV = {
|
const KV = {
|
||||||
'skydusky': SKYDUSKY
|
'skydusky': SKYDUSKY
|
||||||
};
|
};
|
||||||
|
const noauth = ['lidar'];
|
||||||
|
|
||||||
/************************************************************/
|
/************************************************************/
|
||||||
/*
|
/*
|
||||||
|
@ -69,12 +70,10 @@ function BadRequestException(reason) {
|
||||||
* @throws {UnauthorizedException}
|
* @throws {UnauthorizedException}
|
||||||
*/
|
*/
|
||||||
async function verifyCredentials(store, user, pass) {
|
async function verifyCredentials(store, user, pass) {
|
||||||
console.log(`STORE: ${store}`)
|
|
||||||
if (!KV.hasOwnProperty(store)) {
|
if (!KV.hasOwnProperty(store)) {
|
||||||
throw new UnauthorizedException('Invalid password.');
|
throw new UnauthorizedException('Invalid password.');
|
||||||
}
|
}
|
||||||
const KVpass = await KV[store].get(user);
|
const KVpass = await KV[store].get(user);
|
||||||
console.log(`PASS: ${KVpass}`)
|
|
||||||
if (KVpass === 'null' || KVpass !== pass) {
|
if (KVpass === 'null' || KVpass !== pass) {
|
||||||
throw new UnauthorizedException('Invalid password.');
|
throw new UnauthorizedException('Invalid password.');
|
||||||
}
|
}
|
||||||
|
@ -89,20 +88,22 @@ async function handleRequest(request) {
|
||||||
const path = requestURL.pathname.substring(1);
|
const path = requestURL.pathname.substring(1);
|
||||||
const area = path.split('/')[0];
|
const area = path.split('/')[0];
|
||||||
|
|
||||||
// Prompt login
|
if (!noauth.includes(area)) {
|
||||||
if (!request.headers.has('Authorization')) {
|
// Prompt login
|
||||||
return new Response('Please login.', {
|
if (!request.headers.has('Authorization')) {
|
||||||
status: 401,
|
return new Response('Please login.', {
|
||||||
headers: { 'WWW-Authenticate': `Basic realm="${area.toUpperCase()}", charset="UTF-8"` }
|
status: 401,
|
||||||
});
|
headers: { 'WWW-Authenticate': `Basic realm="${area.toUpperCase()}", charset="UTF-8"` }
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Verify login
|
// Verify login
|
||||||
const { user, pass } = basicAuthentication(request);
|
const { user, pass } = basicAuthentication(request);
|
||||||
try {
|
try {
|
||||||
await verifyCredentials(area, user, pass);
|
await verifyCredentials(area, user, pass);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return e;
|
return e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// S3 Client
|
// S3 Client
|
||||||
|
|
Loading…
Reference in New Issue