Skip to content

Commit

Permalink
protect_keylist
Browse files Browse the repository at this point in the history
add, del, qry, refuse protect_keylist ;
qryall, hide protect_keylist ;
  • Loading branch information
crazypeace committed Jan 16, 2024
1 parent 9097d00 commit af380db
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const config = {
shorturl_system: true,//Check value is valid URL && 302 jump to the value
}

// key in protect_keylist can't read, add, del from UI and API
const protect_keylist = [
"password",
]
Expand Down Expand Up @@ -183,6 +184,7 @@ async function handleRequest(request) {
})
}
} else if (req_cmd == "del") {
// Refuse to delete 'password' entry
if (protect_keylist.includes(req_key)) {
return new Response(`{"status":500, "key": "` + req_key + `", "error":"Error: Key in protect_keylist."}`, {
headers: response_header,
Expand All @@ -200,6 +202,13 @@ async function handleRequest(request) {
headers: response_header,
})
} else if (req_cmd == "qry") {
// Refuse to query 'password'
if (protect_keylist.includes(req_key)) {
return new Response(`{"status":500,"key": "` + req_key + `", "error":"Error: Key in protect_keylist."}`, {
headers: response_header,
})
}

let value = await LINKS.get(req_key)
if (value != null) {
return new Response(`{"status":200, "key": "` + req_key + `", "url": "` + value + `", "error":""}`, {
Expand All @@ -224,6 +233,10 @@ async function handleRequest(request) {

for (var i = 0; i < keyList.keys.length; i++) {
let item = keyList.keys[i];
// Hide 'password' from the query all result
if (protect_keylist.includes(item.name)) {
continue;
}
let url = await LINKS.get(item.name);

let newElement = { "key": item.name, "value": url };
Expand Down

0 comments on commit af380db

Please sign in to comment.