Skip to content

Commit

Permalink
feat: ability to adjust thumbnail quality/size and page limit
Browse files Browse the repository at this point in the history
  • Loading branch information
jakowenko committed Sep 20, 2021
1 parent 2fc98ad commit e5207fa
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,22 @@ logs:
level: info
```

### `ui`

```yaml
# ui settings (default: shown below)
ui:
pagination:
# number of results per page
limit: 50

thumbnails:
# value between 0-100
quality: 80
# value in pixels
width: 300
```

## Donations

If you would like to make a donation to support development, please use [GitHub Sponsors](https://github.com/sponsors/jakowenko).
9 changes: 9 additions & 0 deletions api/src/constants/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,13 @@ module.exports = {
logs: {
level: 'info',
},
ui: {
pagination: {
limit: 50,
},
thumbnails: {
quality: 80,
width: 300,
},
},
};
4 changes: 2 additions & 2 deletions api/src/controllers/match.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const filesystem = require('../util/fs.util');
const { tryParseJSON } = require('../util/validators.util');
const { jwt } = require('../util/auth.util');
const process = require('../util/process.util');
const { AUTH, STORAGE } = require('../constants');
const { AUTH, STORAGE, UI } = require('../constants');
const { BAD_REQUEST } = require('../constants/http-status');
const DETECTORS = require('../constants/config').detectors();

Expand Down Expand Up @@ -40,7 +40,7 @@ const format = async (matches) => {
};

module.exports.get = async (req, res) => {
const limit = 100;
const limit = UI.PAGINATION.LIMIT;
const { sinceId, page } = req.query;
const filters = tryParseJSON(req.query.filters);

Expand Down
6 changes: 3 additions & 3 deletions api/src/controllers/storage.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const filesystem = require('../util/fs.util');
const database = require('../util/db.util');
const { tryParseJSON } = require('../util/validators.util');
const { BAD_REQUEST } = require('../constants/http-status');

const { PATH } = require('../constants').STORAGE;
const { QUALITY, WIDTH } = require('../constants').UI.THUMBNAILS;

module.exports.matches = async (req, res) => {
const { box: showBox } = req.query;
Expand Down Expand Up @@ -85,7 +85,7 @@ module.exports.matches = async (req, res) => {

const buffer =
req.query.thumb === ''
? await sharp(source).jpeg({ quality: 75 }).resize(400).withMetadata().toBuffer()
? await sharp(source).jpeg({ quality: QUALITY }).resize(WIDTH).withMetadata().toBuffer()
: fs.readFileSync(source);
res.set('Content-Type', 'image/jpeg');
return res.end(buffer);
Expand All @@ -99,7 +99,7 @@ module.exports.train = async (req, res) => {

const buffer =
req.query.thumb === ''
? await sharp(source).jpeg({ quality: 75 }).resize(400).withMetadata().toBuffer()
? await sharp(source).jpeg({ quality: QUALITY }).resize(WIDTH).withMetadata().toBuffer()
: fs.readFileSync(source);
res.set('Content-Type', 'image/jpeg');

Expand Down

0 comments on commit e5207fa

Please sign in to comment.