diff --git a/.env.example b/.env.example index ad6e6b8..5b87092 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ # -- PixivFE configuration -# Visit https://codeberg.org/VnPower/PixivFE/wiki/Environment-variables for more details +# See ./doc/Environment-variables.md for more details # -- Required # PIXIVFE_TOKEN=changethis # Only set here if not using a secret diff --git a/README.md b/README.md index cee01a6..1d4e060 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ A privacy-respecting alternative front-end for Pixiv that doesn't suck. Questions? Feedback? You can [PM me](https://matrix.to/#/@vnpower:eientei.org) on Matrix! You can also look in [Known Quirks Of PixivFE](spec/quirks.md) to see if your issue already has a known solution. -You can keep track of this project's development [here](https://codeberg.org/VnPower/PixivFE/wiki/Things-to-do). +You can keep track of this project's development [here](spec/Things-to-do.md). ## Features @@ -27,7 +27,7 @@ You can keep track of this project's development [here](https://codeberg.org/VnP You can use PixivFE for personal use! Assuming that you use an operating system that can run POSIX shell scripts, install `go`, clone this repository, modify the `run.sh` file, and profit! I recommend self-hosting your own instance for personal use, instead of relying entirely on official instances. -[How to host PixivFE using Docker and Caddy](https://codeberg.org/VnPower/pixivfe/wiki/Hosting) +[How to host PixivFE using Docker and Caddy](doc/Hosting.md) ## Development @@ -60,7 +60,7 @@ PIXIVFE_DEV=1 go run . | WhateverItWorks | Yes | https://art.whateveritworks.org | | ducks.party | No | https://pixivfe.ducks.party | -[How to host a Pixiv proxy](https://codeberg.org/VnPower/PixivFE/wiki/Hosting-an-image-proxy-server-for-Pixiv) +[How to host a Pixiv proxy](doc/Hosting-an-image-proxy-server-for-Pixiv.md) Hosted one yourself? Create a pull request to add it here! diff --git a/doc/Environment-variables.md b/doc/Environment-variables.md new file mode 100644 index 0000000..2b873bf --- /dev/null +++ b/doc/Environment-variables.md @@ -0,0 +1,43 @@ +Currently, you can only set variables directly in your environment. + +### PIXIVFE_TOKEN +**Required**: Yes + +Authorization is required to fully access Pixiv's Ajax API. This variable will store your Pixiv's account cookie, which will be used by PixivFE for authorization. + +**Notice:** Please read [How to get PIXIVFE_TOKEN](How-to-get-the-cookie-(PIXIVFE_TOKEN).md) to see how can you get your own token and more. + +### PIXIVFE_PORT +**Required**: Yes (no if PIXIVFE_UNIXSOCKET was set) + +Port to run on. For example `PIXIVFE_PORT=8745`. + +### PIXIVFE_UNIXSOCKET +**Required**: Yes (ignored if PIXIVFE_PORT was set) + +UNIX socket to run on. For example `PIXIVFE_UNIXSOCKET=/srv/http/pages/pixivfe`. + +### PIXIVFE_IMAGEPROXY +**Required**: Yes + +See the current [list of image proxies](https://pixivfe.exozy.me/settings). + +The address to proxy images. Pixiv does not allow you to get their images normally. For example, this [image](https://i.pximg.net/img-original/img/2023/06/06/20/30/01/108783513_p0.png). We could bypass this anyway by using NGINX and reverse proxy. [You can host an image proxy server if you want](./Hosting-an-image-proxy-server-for-Pixiv.md). If you wish not to, or unable to get images directly from Pixiv, set this variable. + +### PIXIVFE_USERAGENT +**Required**: No + +Default: Mozilla/5.0 + +The value of the `User-Agent` header, used to make requests to Pixiv's API. + +### PIXIVFE_BASEURL +**Required**: No + +Used to generate meta tags. + +### PIXIVFE_ACCEPTLANGUAGE +**Required**: No +Default: en-US,en;q=0.5 + +The value of the `Accept-Language` header, used to make requests to Pixiv's API. You can change the response's language with this one. \ No newline at end of file diff --git a/doc/Hosting-an-image-proxy-server-for-Pixiv.md b/doc/Hosting-an-image-proxy-server-for-Pixiv.md new file mode 100644 index 0000000..d7a8fd1 --- /dev/null +++ b/doc/Hosting-an-image-proxy-server-for-Pixiv.md @@ -0,0 +1,38 @@ +If you preferred not to use third-party image proxy server, then you could one by yourself! + +To get any images from Pixiv, you just have to change the referer to Pixiv. + + +``` +proxy_cache_path /path/to/cache levels=1:2 keys_zone=pximg:10m max_size=10g inactive=7d use_temp_path=off; + +server { + listen 443 ssl http2; + + ssl_certificate /path/to/ssl_certificate.crt; + ssl_certificate_key /path/to/ssl_certificate.key; + + server_name pximg.example.com; + access_log off; + + location / { + proxy_cache pximg; + proxy_pass https://i.pximg.net; + proxy_cache_revalidate on; + proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; + proxy_cache_lock on; + add_header X-Cache-Status $upstream_cache_status; + proxy_set_header Host i.pximg.net; + proxy_set_header Referer "https://www.pixiv.net/"; + + proxy_cache_valid 200 7d; + proxy_cache_valid 404 5m; + } +} +``` + +Now, just replace `i.pximg.net` with yours, for example the image I mentioned in the environment variable page: `https://i.pximg.net/img-original/img/2023/06/06/20/30/01/108783513_p0.png` -> `https://pximg.example.com/img-original/img/2023/06/06/20/30/01/108783513_p0.png`. + +You can visit this site to know more: https://pixiv.cat/reverseproxy.html. It is also an image proxy server! Try https://i.pixiv.cat/img-original/img/2023/06/06/20/30/01/108783513_p0.png. + +You can also try out [this repo](https://gitler.moe/suwako/imgproxy) from TechnicalSuwako for references. \ No newline at end of file diff --git a/doc/Hosting.md b/doc/Hosting.md new file mode 100644 index 0000000..21d5f87 --- /dev/null +++ b/doc/Hosting.md @@ -0,0 +1,130 @@ +# Hosting + +This page covers multiple methods to install PixivFE. Using [Docker](#docker) is recommended for production use. + +## Prerequisites + +### Getting the token + +PixivFE needs an account token to reach the API. + +You can check out [this page](./How-to-get-the-cookie-(PIXIVFE_TOKEN).md) for detailed information about how to get the token. + +## Installation + +### Docker + +Docker images for PixivFE can be built with support for `amd64` and `arm64` platforms. + +However, there is no Docker image for PixivFE, so you will have to build your own. + +#### Docker Compose + +Deploying PixivFE using Docker Compose requires the Compose plugin to be installed. Follow these [instructions on the Docker Docs](https://docs.docker.com/compose/install) on how to install it. + +##### 1. Setting up the repository + +Clone the repo and `cd` into the directory: + +```bash +git clone https://codeberg.org/VnPower/PixivFE.git && cd PixivFE +``` + +##### 2. Set token + +A [secret](https://docs.docker.com/compose/use-secrets/) is used to provide the token used by PixivFE to fetch content. + +Copy the contents of the `PHPSESSID` cookie into `docker/pixivfe_token.txt`. + +##### 3. Compose! + +```bash +docker compose up -d +``` + +Your PixivFE instance is now up at `localhost:8282`! + +To follow container logs: + +```bash +docker logs -f pixivfe +``` + +#### Docker CLI + +Deploying PixivFE using Docker CLI may be easier than Docker Compose, but requires a slightly different setup. + +Furthermore, the `buildx` Docker plugin needs to be installed. Follow these [instructions on the Docker `buildx` repo](https://github.com/docker/buildx?tab=readme-ov-file#installing) on how to install it. + +##### 1. Setting up the repository + +```bash +git clone https://codeberg.org/VnPower/PixivFE.git && cd PixivFE +``` + +##### 2. Building the image + +For `amd64` platforms: + +```bash +docker buildx build --platform linux/amd64 -t vnpower/pixivfe:latest --load . +``` + +For `arm64` platforms: + +```bash +docker buildx build --platform linux/arm64 -t vnpower/pixivfe:latest-arm64 --load . +``` + +##### 3. Deploying PixivFE + +Deploy PixivFE: + +``` +docker run -d --name pixivfe -p 8282:8282 vnpower/pixivfe:latest +``` + +Deploy using a different port on the host (in this case, port 8080): + +``` +docker run -d --name pixivfe -p 8080:8282 vnpower/pixivfe:latest +``` + +> **Note**: +> +> If deploying on an `arm64` platform, use the `vnpower/pixivfe:latest-arm64` image instead. + +If you're using a reverse proxy in front of PixivFE, prefix the port numbers with `127.0.0.1` so that PixivFE only listens on the host port **locally**. For example, if the host port for PixivFE is `8080`, specify `127.0.0.1:8080:8282`. + +### Binary with Caddy reverse proxy + +Clone the repository and install the dependencies. + +```bash +git clone https://codeberg.org/VnPower/PixivFE.git && cd PixivFE +go install +``` + +You may wanted to check out some of the environment variables used by PixivFE before continuing. + +After that, run `go run main.go`. And PixivFE should be running now! + +[Caddy](https://caddyserver.com/) is a great alternative to NGINX, because it is written in Go but also easy to config. + +Install Caddy using your package manager. + +After installing Caddy, make sure that you are inside PixivFE's directory. Then, create a file named `Caddyfile`. You should see something like this: + +``` +example.com { + reverse_proxy localhost:8282 +} +``` + +Change `example.com` to your domain, also change `8282` if you set the PixivFE's port to something else. + +Finally, run `caddy run`. + +## Acknowledgement + +- [Keep Caddy Running](https://caddyserver.com/docs/running#keep-caddy-running) diff --git a/doc/How-to-get-the-cookie-(PIXIVFE_TOKEN).md b/doc/How-to-get-the-cookie-(PIXIVFE_TOKEN).md new file mode 100644 index 0000000..0c208e4 --- /dev/null +++ b/doc/How-to-get-the-cookie-(PIXIVFE_TOKEN).md @@ -0,0 +1,43 @@ +# How to get the cookie (PIXIVFE_TOKEN) + +This guide covers how to get your Pixiv account's cookie to authenticate. + +> **Note**: +> +> You should create an entirely new account for this to avoid account theft. And also, PixivFE will get contents **from your account.** You might not want people to know what kind of illustrations you like :P. For now, the only page that may contain contents that is relevant to you is the discovery page. Be careful if you are using your main account. + +## Firefox-based + +1. Log in to your Pixiv account of choice. You should be greeted with the landing page with logging in. If you are already logged in, go to the landing page. + +![The URL of the landing page](https://files.catbox.moe/7dbv3e.png) + +2. Hit `F12` to open up the developer tools. Then, go to the `Storage` tab. + +![Storage tab on Firefox](https://files.catbox.moe/mra6rs.png) + +3. At the left side, open up the `Cookies` section. Then select `www.pixiv.net`, this is the place where you will get your cookie. + The page now should look like the screenshot below. Select the cookie with the key `PHPSESSID`, the value next to it is your account's token. + +![Cookie on Firefox](https://files.catbox.moe/zb16o8.png) + +4. Copy it and set the environment variable! If deploying using Docker Compose, copy it into `docker/pixivfe_token.txt` instead. + +## Chrome-based + +1. Log in to your Pixiv account of choice. You should be greeted with the landing page with logging in. If you are already logged in, go to the landing page. + +2. Hit `F12` to open up the developer tools. Then, go to the `Applications` tab. + +3. At the left side, you can see the `Storage` section. Inside of that section, there is an another section called `Cookies`, open up the `Cookies` section, then select `www.pixiv.net`. This is the place where you will get your cookie. + The page now should look like the screenshot below. Select the cookie with the key `PHPSESSID`, the value next to it is your account's token. + +![PHPSESSID on Chrome-based browsers](https://files.catbox.moe/8wu9f0.png) + +4. Copy it and set the environment variable! If deploying using Docker Compose, copy it into `docker/pixivfe_token.txt` instead. + +## Note + +- The token should look something like this: `123456_AaBbccDDeeFFggHHIiJjkkllmMnnooPP`. The part before the underline is your member ID, the part after the underline is just a random string. +- The token will reset when you logout. Please double-check that your token is still valid before reporting any issues. +- Chrome-based browsers and some content was taken from [this page by Nandaka.](https://github.com/Nandaka/PixivUtil2/wiki#pixiv-login-using-cookie) diff --git a/docker-compose.yml b/docker-compose.yml index a5ad62b..eec49a3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,5 +29,5 @@ services: secrets: pixivfe_token: # Copy the contents of the `PHPSESSID` cookie into `pixivfe_token.txt` - # See https://codeberg.org/VnPower/pixivfe/wiki/How-to-get-the-cookie-%28PIXIVFE_TOKEN%29 for instructions + # See ./doc/How-to-get-the-cookie-(PIXIVFE_TOKEN) for instructions file: ./docker/pixivfe_token.txt diff --git a/run.sh b/run.sh index 7c94142..0a25e44 100644 --- a/run.sh +++ b/run.sh @@ -3,7 +3,7 @@ # Update the program every time you run? # git pull -# Visit https://codeberg.org/VnPower/PixivFE/wiki/Environment-variables for more details +# Visit ./doc/Environment-variables.md for more details export PIXIVFE_TOKEN=token_123456 export PIXIVFE_IMAGEPROXY=pximg.cocomi.cf # export PIXIVFE_UNIXSOCKET=/srv/http/pages/pixivfe diff --git a/views/pages/login.jet.html b/views/pages/login.jet.html deleted file mode 100644 index 802842b..0000000 --- a/views/pages/login.jet.html +++ /dev/null @@ -1,38 +0,0 @@ -
-

Login with your account

-

- In order to enable the landing page and other features, you will have to - login. -

-

Supported features:

- -

- You can only login using your account's cookie, check out - this page - to see how to get it. -

-

- Note that you will get logged out automatically every time the server - updates, if you are logged in before but got logged out recently, it is - probably because the instance owner restarted the server. -

-
- - -
-
-

Logout

-

- You can safely logout here. This button will just delete the token directly - from this session. -

-
- -
-
diff --git a/views/pages/settings.jet.html b/views/pages/settings.jet.html index 7c901d7..9d3ee69 100644 --- a/views/pages/settings.jet.html +++ b/views/pages/settings.jet.html @@ -8,7 +8,7 @@

You can only login using your account's cookie, check out this page to see how to get it.