Get using multiple identifiers with automerge none.
This commit is contained in:
parent
20ffaa3e68
commit
7c439b5963
@ -108,19 +108,19 @@ function getIds(url: string): Array<string> {
|
|||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateResponseBody(digest: string, data: string) {
|
function generateResponseBody(digest: string, data: string | boolean): string {
|
||||||
let response = {
|
let response = {
|
||||||
id: digest,
|
id: digest,
|
||||||
status: 0,
|
status: 0,
|
||||||
headers: {},
|
headers: {},
|
||||||
body: ''
|
body: ''
|
||||||
}
|
}
|
||||||
const responseContentLength = (new TextEncoder().encode(data)).length;
|
if (typeof data === 'boolean' || data === undefined) {
|
||||||
if (data === undefined) {
|
|
||||||
response.body = `Metadata for identifier ${digest} not found!`;
|
response.body = `Metadata for identifier ${digest} not found!`;
|
||||||
response.status = 404;
|
response.status = 404;
|
||||||
response.headers = {"Content-Type": "text/plain"}
|
response.headers = {"Content-Type": "text/plain"}
|
||||||
} else {
|
} else {
|
||||||
|
const responseContentLength = (new TextEncoder().encode(data)).length;
|
||||||
response.body = data;
|
response.body = data;
|
||||||
response.status = 200;
|
response.status = 200;
|
||||||
response.headers = {
|
response.headers = {
|
||||||
@ -156,6 +156,11 @@ async function processRequest(req, res) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (req.url.includes('id')) {
|
if (req.url.includes('id')) {
|
||||||
|
if (req.method !== 'GET') {
|
||||||
|
res.writeHead(405, {"Content-Type": "text/plain"});
|
||||||
|
res.end();
|
||||||
|
return;
|
||||||
|
}
|
||||||
digest = getIds(req.url);
|
digest = getIds(req.url);
|
||||||
} else {
|
} else {
|
||||||
digest = parseDigest(req.url.substring(1));
|
digest = parseDigest(req.url.substring(1));
|
||||||
@ -239,6 +244,22 @@ async function processRequest(req, res) {
|
|||||||
// break;
|
// break;
|
||||||
|
|
||||||
case 'get:automerge:none':
|
case 'get:automerge:none':
|
||||||
|
if (digest instanceof Array) {
|
||||||
|
let response = [];
|
||||||
|
for (let dg of digest) {
|
||||||
|
const metadata = await handlers.handleNoMergeGet(db, dg, keystore);
|
||||||
|
response.push(generateResponseBody(dg, metadata));
|
||||||
|
}
|
||||||
|
const responseContentLength = (new TextEncoder().encode(response.toString())).length;
|
||||||
|
res.writeHead(207, {
|
||||||
|
"Access-Control-Allow-Origin": "*",
|
||||||
|
"Content-Type": contentType,
|
||||||
|
"Content-Length": responseContentLength,
|
||||||
|
});
|
||||||
|
res.write(response.toString());
|
||||||
|
res.end();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
r = await handlers.handleNoMergeGet(db, digest, keystore);
|
r = await handlers.handleNoMergeGet(db, digest, keystore);
|
||||||
if (r == false) {
|
if (r == false) {
|
||||||
res.writeHead(404, {"Content-Type": "text/plain"});
|
res.writeHead(404, {"Content-Type": "text/plain"});
|
||||||
@ -246,6 +267,7 @@ async function processRequest(req, res) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
content = r;
|
content = r;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user