~mser/emote-server

671a8f4c7baedc71e83d3af291ae8fdad011052a — Michael Serajnik 8 months ago 07adda6 + 91d4211 1.2.0
Merge branch 'release/1.2.0'
7 files changed, 89 insertions(+), 2 deletions(-)

M .build.yml
M CHANGELOG.md
M README.md
M index.js
M package.json
M src/config/index.js
M src/util/emotes.js
M .build.yml => .build.yml +13 -0
@@ 19,7 19,20 @@ tasks:
      sudo service docker start
  - build: |
      cd $project

      version=$(node -e "console.log(require('./package.json').version)")

      set +e

      docker_ps_return=1
      until [ ${docker_ps_return} -eq 0 ]; do
        docker ps >/dev/null 2>&1
        docker_ps_return=$?
        sleep 1
      done

      set -e

      docker build . -t $docker_image:latest -t $docker_image:$version
  - publish: |
      cat ~/.docker-hub-personal-access-token | docker login --username $docker_username --password-stdin

M CHANGELOG.md => CHANGELOG.md +7 -0
@@ 8,6 8,12 @@ and this project adheres to

## [Unreleased]

## [1.2.0] - 2021-04-02

### Added

+ Route for deleting all frozen emotes (`DELETE /frozen-emotes`)

## [1.1.0] - 2021-04-02

### Added


@@ 21,5 27,6 @@ and this project adheres to
+ Initial release

[Unreleased]: https://git.sr.ht/~mser/emote-server/tree/develop
[1.2.0]: https://git.sr.ht/~mser/emote-server/tree/1.2.0
[1.1.0]: https://git.sr.ht/~mser/emote-server/tree/1.1.0
[1.0.0]: https://git.sr.ht/~mser/emote-server/tree/1.0.0

M README.md => README.md +23 -0
@@ 28,6 28,7 @@ API.
        + [Listing emotes](#listing-emotes)
        + [Getting emotes](#getting-emotes)
        + [Getting frozen emotes](#getting-frozen-emotes)
        + [Deleting frozen emotes](#deleting-frozen-emotes)
+ [Maintainer](#maintainer)
+ [Contribute](#contribute)
+ [License](#license)


@@ 301,6 302,28 @@ __Possible errors:__
+ `GetError`
+ `GenerationError`

###### Deleting frozen emotes

Deletes all frozen emotes (without touching their source emotes). Useful for
forcing regeneration (e.g., after overwriting an emote with another of the same
name).

__Route:__ `DELETE /frozen-emotes`

__Response on success:__

```json5
{
  "success": true,
  "message": "Delete"
}
```

__Possible errors:__

+ `AccessKeyError`
+ `DeleteError`

## Maintainer

[Michael Serajnik][maintainer]

M index.js => index.js +23 -0
@@ 214,4 214,27 @@ service.get('/frozen-emotes/:emote', async (req, res) => {
    .pipe(res)
})

service.delete('/frozen-emotes', async (req, res) => {
  if (config.accessKey !== '') {
    try {
      await schemas.emotes.validateAsync({
        accessKey: req.headers.authorization ||
          (req.query.accessKey ? `Bearer ${req.query.accessKey}` : null)
      })
    } catch {
      return res.send({
        success: false,
        error: 'AccessKeyError'
      }, 401)
    }
  }

  const deleteResponse = await emotes.deleteFrozenEmotes()

  res.send({
    success: deleteResponse.success,
    [deleteResponse.success ? 'message' : 'error']: deleteResponse.message
  }, deleteResponse.code)
})

module.exports = service

M package.json => package.json +1 -1
@@ 1,6 1,6 @@
{
  "name": "emote-server",
  "version": "1.1.0",
  "version": "1.2.0",
  "description": "A simple application to list and serve emotes",
  "author": "Michael Serajnik <m@mser.at>",
  "license": "AGPL-3.0-or-later",

M src/config/index.js => src/config/index.js +1 -1
@@ 13,7 13,7 @@ if (frozenEmotesPath.startsWith('.')) {
}

module.exports = {
  version: '1.1.0',
  version: '1.2.0',
  apiVersion: 1,
  publicUrl: process.env.EMOTE_SERVER_PUBLIC_URL || 'http://localhost',
  port: process.env.EMOTE_SERVER_PORT || 8000,

M src/util/emotes.js => src/util/emotes.js +21 -0
@@ 123,6 123,27 @@ module.exports = {
      code: 200
    }
  },
  async deleteFrozenEmotes () {
    const emotePaths = await fg(`${config.frozenEmotesPath}/*.png`)

    for (const emotePath of emotePaths) {
      try {
        await fsp.unlink(emotePath)
      } catch {
        return {
          success: false,
          message: 'DeleteError',
          code: 500
        }
      }
    }

    return {
      success: true,
      message: 'Delete',
      code: 200
    }
  },
  async getMimeType (filePath) {
    await fsp.access(filePath, fs.constants.F_OK)
    const fileType = await FileType.fromFile(filePath)