Skip to content

Commit

Permalink
feat: add routes for /img/ with configurable upload limit
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalsadhu committed Aug 13, 2024
1 parent 00c85c1 commit 0f6bda7
Show file tree
Hide file tree
Showing 3 changed files with 709 additions and 0 deletions.
137 changes: 137 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as utils from './utils.js';
* @property {string} [notFoundCacheControl="public, max-age=5"]
* @property {number} [pkgMaxFileSize=10000000] The limit in bytes before PUT /pkg/ starts returning 413 Content Too Large
* @property {number} [mapMaxFileSize=1000000] The limit in bytes before PUT /map/ starts returning 413 Content Too Large
* @property {number} [imgMaxFileSize=10000000] The limit in bytes before PUT /img/ starts returning 413 Content Too Large
*/

const EikService = class EikService {
Expand All @@ -34,6 +35,7 @@ const EikService = class EikService {
aliasCacheControl,
pkgMaxFileSize,
mapMaxFileSize,
imgMaxFileSize,
} = options;
this._notFoundCacheControl =
notFoundCacheControl || 'public, max-age=5';
Expand Down Expand Up @@ -104,6 +106,12 @@ const EikService = class EikService {
logger,
pkgMaxFileSize,
});
this._imgPut = new eik.http.PkgPut({
organizations,
sink,
logger,
pkgMaxFileSize: imgMaxFileSize,
});
this._mapGet = new eik.http.MapGet({ organizations, sink, logger });
this._mapPut = new eik.http.MapPut({
organizations,
Expand Down Expand Up @@ -351,6 +359,21 @@ const EikService = class EikService {
reply.redirect(outgoing.location);
};

const imgPutRoute = async (request, reply) => {
const params = utils.sanitizeParameters(request.raw.url);
const outgoing = await this._imgPut.handler(
request.raw,
request.user,
params.type,
params.name,
params.version,
);
reply.header('cache-control', outgoing.cacheControl);
reply.type(outgoing.mimeType);
reply.code(outgoing.statusCode);
reply.redirect(outgoing.location);
};

const mapGetRoute = async (request, reply) => {
const params = utils.sanitizeParameters(request.raw.url);
const outgoing = await this._mapGet.handler(
Expand Down Expand Up @@ -547,6 +570,56 @@ const EikService = class EikService {
pkgPutRoute,
);

//
// Image Packages
//

// Get public IMG package - scoped
// curl -X GET http://localhost:4001/img/@cuz/fuzz/8.4.1/main/picture.jpg
app.get(
`/${eik.prop.base_img}/@:scope/:name/:version/*`,

Check failure on line 580 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 580 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 580 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 580 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.
pkgGetRoute,
);

// Get public IMG package - non-scoped
// curl -X GET http://localhost:4001/img/fuzz/8.4.1/main/picture.jpg
app.get(`/${eik.prop.base_img}/:name/:version/*`, pkgGetRoute);

Check failure on line 586 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 586 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 586 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 586 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.

// Get IMG package overview - scoped
// curl -X GET http://localhost:4001/img/@cuz/fuzz/8.4.1/
app.get(
`/${eik.prop.base_img}/@:scope/:name/:version`,

Check failure on line 591 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 591 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 591 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 591 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.
pkgLogRoute,
);

// Get IMG package overview - non-scoped
// curl -X GET http://localhost:4001/img/fuzz/8.4.1/
app.get(`/${eik.prop.base_img}/:name/:version`, pkgLogRoute);

Check failure on line 597 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 597 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 597 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 597 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.

// Get IMG package versions - scoped
// curl -X GET http://localhost:4001/img/@cuz/fuzz/
app.get(`/${eik.prop.base_img}/@:scope/:name`, versionsGetRoute);

Check failure on line 601 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 601 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 601 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 601 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.

// Get IMG package versions - non-scoped
// curl -X GET http://localhost:4001/img/fuzz/
app.get(`/${eik.prop.base_img}/:name`, versionsGetRoute);

Check failure on line 605 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 605 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 605 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 605 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.

// Put IMG package - scoped
// curl -X PUT -i -F filedata=@archive.tgz http://localhost:4001/img/@cuz/fuzz/8.4.1/
app.put(
`/${eik.prop.base_img}/@:scope/:name/:version`,

Check failure on line 610 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 610 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 610 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 610 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.
authOptions,
imgPutRoute,
);

// Put IMG package - non-scoped
// curl -X PUT -i -F filedata=@archive.tgz http://localhost:4001/img/fuzz/8.4.1/
app.put(
`/${eik.prop.base_img}/:name/:version`,

Check failure on line 618 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 618 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 618 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 618 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.
authOptions,
imgPutRoute,
);

//
// Import Maps
//
Expand Down Expand Up @@ -714,6 +787,70 @@ const EikService = class EikService {
aliasDelRoute,
);

//
// Alias Image Packages
//

// curl -X GET -L http://localhost:4001/img/@cuz/fuzz/v8
app.get(
`/${eik.prop.base_img}/@:scope/:name/v:alias`,

Check failure on line 796 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 796 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 796 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 796 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.
aliasGetRoute,
);

// curl -X GET -L http://localhost:4001/img/fuzz/v8
app.get(`/${eik.prop.base_img}/:name/v:alias`, aliasGetRoute);

Check failure on line 801 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 801 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 801 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 18)

Property 'base_img' does not exist on type 'typeof prop'.

Check failure on line 801 in lib/main.js

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 20)

Property 'base_img' does not exist on type 'typeof prop'.

// curl -X GET -L http://localhost:4001/img/@cuz/fuzz/v8/main/index.js
app.get(
`/${eik.prop.base_img}/@:scope/:name/v:alias/*`,
aliasGetRoute,
);

// curl -X GET -L http://localhost:4001/img/fuzz/v8/main/index.js
app.get(`/${eik.prop.base_img}/:name/v:alias/*`, aliasGetRoute);

// curl -X PUT -i -F version=8.4.1 http://localhost:4001/img/@cuz/fuzz/v8
app.put(
`/${eik.prop.base_img}/@:scope/:name/v:alias`,
authOptions,
aliasPutRoute,
);

// curl -X PUT -i -F version=8.4.1 http://localhost:4001/img/fuzz/v8
app.put(
`/${eik.prop.base_img}/:name/v:alias`,
authOptions,
aliasPutRoute,
);

// curl -X POST -i -F version=8.4.1 http://localhost:4001/img/@cuz/lit-html/v8
app.post(
`/${eik.prop.base_img}/@:scope/:name/v:alias`,
authOptions,
aliasPostRoute,
);

// curl -X POST -i -F version=8.4.1 http://localhost:4001/img/lit-html/v8
app.post(
`/${eik.prop.base_img}/:name/v:alias`,
authOptions,
aliasPostRoute,
);

// curl -X DELETE http://localhost:4001/img/@cuz/fuzz/v8
app.delete(
`/${eik.prop.base_img}/@:scope/:name/v:alias`,
authOptions,
aliasDelRoute,
);

// curl -X DELETE http://localhost:4001/img/fuzz/v8
app.delete(
`/${eik.prop.base_img}/:name/v:alias`,
authOptions,
aliasDelRoute,
);

//
// Alias Import Maps
//
Expand Down
198 changes: 198 additions & 0 deletions tap-snapshots/test/img.test.js.test.cjs

Large diffs are not rendered by default.

Loading

0 comments on commit 0f6bda7

Please sign in to comment.