Mostly complete (read-only) compatibility with web library (#4270)

- Add pagination, limits, and Link header
- Add schema endpoints and dummy /settings endpoint
- Add /file endpoints
  - Browser security restrictions prevent the web library from actually loading
    the file: URIs that the local API returns, but out-of-browser use will work
    fine
- Add toResponseJSONAsync() DataObject function: delegates to toResponseJSON()
  by default, adds information that requires awaiting promises
  - Best attachment (links.attachment) and file size (links.enclosure.length)
    for items, meta.numItems for groups
  - Separate function for compatibility with the existing test code that uses
    toResponseJSON(), but we could consider unifying

This commit does not add the Access-Control headers that allow webpages to make
requests to the local API, since I don't think we actually want that.
This commit is contained in:
Abe Jellinek 2022-10-04 12:23:31 -04:00 committed by Dan Stillman
parent 44d9530ecf
commit 5d197e4b12
6 changed files with 351 additions and 45 deletions

View file

@ -131,6 +131,18 @@ describe("Local API Server", function () {
assert.isTrue(response.links.up.href.includes('/api/'));
assert.isTrue(response.links.enclosure.href.startsWith('file:'));
});
it("should return file URL from /file/view/url", async function () {
let { response } = await apiGet(`/users/0/items/${subcollectionAttachment.key}/file/view/url`, { responseType: 'text' });
assert.isTrue(response.startsWith('file:'));
});
// followRedirects: false not working?
it.skip("should redirect to file URL from /file/view", async function () {
let request = await apiGet(`/users/0/items/${subcollectionAttachment.key}/file/view`,
{ responseType: 'text', followRedirects: false });
assert.isTrue(request.getResponseHeader('Location').startsWith('file:'));
});
});
describe("?itemType", function () {