!CONFIG.disable_comments <=> CONFIG.use_api

This commit is contained in:
3nprob 2021-10-07 15:00:50 +09:00
parent 9d769b2360
commit 5a7baef470
3 changed files with 52 additions and 13 deletions

View File

@ -14,6 +14,20 @@ Inspired by and (soon) integratable with:
* [nitter](https://github.com/zedeus/nitter)
* [bibliogram](https://sr.ht/~cadence/bibliogram/)
This is currently very early stage software. Some things left to implement (contributions welcome!):
[ ] Localization/internationalization
[ ] Pretty CSS styling
[ ] Automatically fetch / rotate / renew client ID
[ ] Support for other popular image sites than only imgur
[ ] Prometheus metrics
Things that are *currently* considered out of scope:
* Uploading/commenting/voting/etc - rimgu is read-only for now.
* Caching, authentication, serving HTTPS, rate limiting etc - Just use a load balancer like haproxy/envoy/nginx/traefik/caddy.
* Anything requiring client-side JS or client-side directly interacting with upstream servers
## Building
### Locally
@ -47,3 +61,29 @@ $ docker run -p 8080:8080 -e -it RIMGU_ADDRESS=0.0.0.0 -e RIMGU_PORT=8080 rimgu:
## Configuration
Rimgu is configured via environment variables. See available variable in [src/config.ts](./src/config.ts).
### API and client ID
Media and galleries can be scraped without authorization through the public web interface.
Some imgur functionality (comments, full albums) requires a provisioned client ID to authenticate requests.
You can get a client ID by opening https://imgur.com in a web browser and looking for requests to `https://api.imgur.com/...?client_id=1234567deadbeef` under "Network" in the developer console.
*To run without API/key*: `RIMGU_USE_API=false`
*To run with API/key*: `RIMGU_USE_API=true RIMGU_IMGUR_CLIENT_ID=1234567deadbeef`
This key may be used to track you and could be banned when overused. Keep this in mind before exposing a public instance with a client key associated with your personal imgur account. Consider any ToS you may have signed before associating a personal imgur account with a public instance.
## Contributing
PRs are welcome! Before submitting a PR, please make sure linting passes successfully:
```
$ npm run lint
```
This software is released under the AGPL 3.0 license. In short, this means that if you make any modifications to the code and then publish the result (e.g. by hosting the result on a webserver), you must publicly distribute your changes and declare that they also use AGPL 3.0.
You are also requested to not remove attribution and donation information from forks and publications.

View File

@ -5,6 +5,6 @@ export default {
http_proxy: process.env.RIMGU_HTTP_PROXY || null,
https_proxy: process.env.RIMGU_HTTPS_PROXY || null,
imgur_client_id: process.env.RIMGU_IMGUR_CLIENT_ID || null,
disable_comments: process.env.RIMGU_DISABLE_COMMENTS === 'true',
use_api: process.env.RIMGU_USE_API !== 'false',
page_title: process.env.RIMGU_PAGE_TITLE || 'rimgu',
};

View File

@ -19,21 +19,20 @@ export const handleMedia = async (request: Hapi.Request, h: Hapi.ResponseToolkit
export const handleAlbum = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
// https://imgur.com/a/DfEsrAB
const albumID = request.params.albumID;
if (CONFIG.disable_comments) {
const url = await fetchAlbumURL(albumID);
return h.view('bare-album', {
url,
pageTitle: CONFIG.page_title,
util,
});
} else {
if (CONFIG.use_api) {
const album = await fetchAlbum(albumID);
return h.view('gallery', {
...album,
pageTitle: CONFIG.page_title,
util,
});
} else {
const url = await fetchAlbumURL(albumID);
return h.view('bare-album', {
url,
pageTitle: CONFIG.page_title,
util,
});
}
};
@ -50,9 +49,9 @@ export const handleTag = (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
export const handleGallery = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
const galleryID = request.params.galleryID;
const gallery = await fetchGallery(galleryID);
const comments = CONFIG.disable_comments
? null
: await fetchComments(galleryID);
const comments = CONFIG.use_api
? await fetchComments(galleryID)
: null;
return h.view('gallery', {
...gallery,
comments,