Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mokeyjay committed Dec 10, 2023
2 parents 55f8d05 + 8fa671e commit 88ce973
Show file tree
Hide file tree
Showing 30 changed files with 628 additions and 429 deletions.
20 changes: 20 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ghcr.io/mokeyjay/pixiv-widget-image:main

COPY . /var/www/html
COPY .docker/config.php /var/www/html/config.php
COPY .docker/nginx-site.conf /etc/nginx/conf.d/default.conf
COPY .docker/start.sh /root/start.sh

COPY .docker/crontab /etc/cron.d/pixiv-cron-job
RUN chmod 0644 /etc/cron.d/pixiv-cron-job && \
crontab /etc/cron.d/pixiv-cron-job

ENV TZ=Asia/Shanghai

LABEL Author="mokeyjay<[email protected]>"
LABEL Version="2023.11.20"
LABEL Description="Pixiv 每日排行榜小挂件"

CMD cron && \
chmod +x /root/start.sh && \
/root/start.sh
18 changes: 10 additions & 8 deletions docker/config.php → .docker/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

use app\Libs\Env;

Env::init();

return [
'url' => Env::getStr('URL'),

Expand All @@ -30,22 +32,22 @@

'image_hosting_extend' => [
'tietuku' => [
'token' => Env::getStr('IMAGE_HOSTING_EXTEND-TIETUKU-TOKEN'),
'token' => Env::getStr('IMAGE_HOSTING_EXTEND_TIETUKU_TOKEN'),
],
'smms' => [
'token' => Env::getStr('IMAGE_HOSTING_EXTEND-SMMS-TOKEN'),
'token' => Env::getStr('IMAGE_HOSTING_EXTEND_SMMS_TOKEN'),
],
'riyugo' => [
'url' => Env::getStr('IMAGE_HOSTING_EXTEND-RIYUGO-URL'),
'upload_path' => Env::getStr('IMAGE_HOSTING_EXTEND-RIYUGO-UPLOAD-PATH'),
'unique_id' => Env::getStr('IMAGE_HOSTING_EXTEND-RIYUGO-UNIQUE-ID'),
'token' => Env::getStr('IMAGE_HOSTING_EXTEND-RIYUGO-TOKEN'),
'url' => Env::getStr('IMAGE_HOSTING_EXTEND_RIYUGO_URL'),
'upload_path' => Env::getStr('IMAGE_HOSTING_EXTEND_RIYUGO_UPLOAD_PATH'),
'unique_id' => Env::getStr('IMAGE_HOSTING_EXTEND_RIYUGO_UNIQUE_ID'),
'token' => Env::getStr('IMAGE_HOSTING_EXTEND_RIYUGO_TOKEN'),
],
],

'disable_web_job' => Env::getBool('DISABLE_WEB_JOB', true),

'static_cdn' => Env::getStr('STATIC_CDN', 'bytedance'),

'header_script' => Env::getStr('HEADER_SCRIPT', ''),

'ranking_type' => Env::getStr('RANKING_TYPE', ''),
];
2 changes: 2 additions & 0 deletions .docker/crontab
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*/30 * * * * cd /var/www/html/ && /usr/local/bin/php index.php -j=refresh
30 1 * * * cd /var/www/html/ && /usr/local/bin/php index.php -j=clear-log
29 changes: 29 additions & 0 deletions .docker/nginx-site.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
server {
listen 80;
listen [::]:80;
server_name _;
root /var/www/html;
index index.php;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

location ~ /\. {
deny all;
}

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
21 changes: 21 additions & 0 deletions .docker/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

echo '' > /etc/nginx/sites-enabled/default

cd /var/www/html
# 将环境变量保存起来,免得 crontab 读不到
env=("URL" "BACKGROUND_COLOR" "LIMIT" "SERVICE" "LOG_LEVEL" "PROXY" "CLEAR_OVERDUE" "COMPRESS" "IMAGE_HOSTING" "IMAGE_HOSTING_EXTEND_TIETUKU_TOKEN" "IMAGE_HOSTING_EXTEND_SMMS_TOKEN" "IMAGE_HOSTING_EXTEND_RIYUGO_URL" "IMAGE_HOSTING_EXTEND_RIYUGO_UPLOAD_PATH" "IMAGE_HOSTING_EXTEND_RIYUGO_UNIQUE_ID" "IMAGE_HOSTING_EXTEND_RIYUGO_TOKEN" "DISABLE_WEB_JOB" "HEADER_SCRIPT" "RANKING_TYPE")
file=".env"
> $file
for var in "${env[@]}"
do
# 部分环境变量值含有空格、换行,得用双引号包起来,不然 source 时会报错
value="${!var}"
value="${value//\"/\\\"}"
echo "$var=\"$value\"" >> $file
done

chown -R www-data:www-data /var/www/html

php-fpm -D
nginx -g 'daemon off;'
56 changes: 56 additions & 0 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: 推送开发用的 docker 镜像
on:
push:
branches:
- 'develop'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
push_to_registry:
name: 构建并推送
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
# https://github.com/actions/checkout
- name: 拉取代码
uses: actions/checkout@v4
with:
ref: develop

# https://github.com/docker/login-action
- name: 登录到 ghcr
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# https://github.com/docker/metadata-action
- name: 提取事件元数据
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# https://github.com/docker/setup-buildx-action
- name: 使用 buildx 作为构建器
uses: docker/setup-buildx-action@v3

# https://github.com/docker/build-push-action
- name: 构建并推送
uses: docker/build-push-action@v5
with:
context: .
file: .docker/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
45 changes: 23 additions & 22 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,64 @@ name: 推送 Docker 镜像
# 触发 action 的事件
on:
push:
# main 分支有推送时触发
# master 分支有推送时触发
branches:
- 'master'
# tag 新建时触发
tags:
- '*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
push_to_registry:
name: 推送到 Docker Hub
name: 构建并推送
# 基于指定平台构建。有 win、ubuntu、mac 可选
# 消耗的分钟倍数:linux 1x、win 2x、mac 10x
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
# https://github.com/actions/checkout
- name: 拉取代码
uses: actions/checkout@v3
uses: actions/checkout@v4

# https://github.com/docker/login-action
- name: 登录到 Docker hub
uses: docker/login-action@v2
- name: 登录到 ghcr
uses: docker/login-action@v3
with:
# 登录用的账号密码。在项目的 Settings -> Secrets and variables -> Actions 中配置
username: ${{ secrets.DOCKERHUB_USERNAME }}
# 在 DockerHub 的 Account Settings -> Security -> Access Token 中配置
password: ${{ secrets.DOCKERHUB_TOKEN }}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# 从触发此次 action 的事件中提取源数据(tag、label 什么的)
# https://github.com/docker/metadata-action
- name: 提取事件元数据
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
# 提取出来的源数据用于这个镜像
images: mokeyjay/pixiv-daily-ranking-widget
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# 使用 buildx 作为构建器,以支持多平台构建之类的能力
# https://github.com/docker/setup-buildx-action
- name: 使用 buildx 作为构建器
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

# https://github.com/docker/build-push-action
- name: 构建并推送
uses: docker/build-push-action@v3
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
file: .docker/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64

# https://github.com/peter-evans/dockerhub-description
- name: 更新镜像描述
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: mokeyjay/pixiv-daily-ranking-widget
cache-from: type=gha
cache-to: type=gha,mode=max
Binary file added .test/pic.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions .test/test_image_hosting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use app\Libs\Config;
use app\ImageHosting\ImageHosting;

define("BASE_PATH", dirname(__FILE__, 2) . DIRECTORY_SEPARATOR);
const APP_PATH = BASE_PATH . 'app' . DIRECTORY_SEPARATOR;
const STORAGE_PATH = BASE_PATH . 'storage' . DIRECTORY_SEPARATOR;
const IS_CLI = PHP_SAPI === 'cli';
const TEST_PATH = BASE_PATH . '.test' . DIRECTORY_SEPARATOR;

require APP_PATH . 'autoload.php';

Config::init();

$skip = ['Riyugo', 'Smms', 'Tietuku', 'ImageHosting', 'Local', '.', '..'];
foreach (scandir(APP_PATH . 'ImageHosting') as $fileName) {

$className = pathinfo($fileName, PATHINFO_FILENAME);
if (in_array($className, $skip) || empty($className)) {
continue;
}

$imageHosting = ImageHosting::make($className);
if ($url = $imageHosting->upload(TEST_PATH . 'pic.jpg')) {
var_dump($className . '成功: ' . $url);
} else {
var_dump($className . '失败: ' . $url);
}
}
47 changes: 23 additions & 24 deletions README.en.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<a href="https://github.com/mokeyjay/Pixiv-daily-ranking-widget/blob/master/README.md">中文</a>
<br><br>
Want to add a <span style="font-weight: bold">Pixiv Daily Ranking Widget</span> to your website? It's a matter of one line of code!
<a href="https://cloud.mokeyjay.com/pixiv/demo.html" target="_blank">DEMO</a>
<a href="https://pixiv.mokeyjay.com/demo.html" target="_blank">DEMO</a>
</p>

## ✨ Features
Expand All @@ -17,7 +17,7 @@
## 🤔 How to use
Just add the below code to your page
```html
<iframe src="https://cloud.mokeyjay.com/pixiv" style="width:240px; height:380px; border: 0"></iframe>
<iframe src="https://pixiv.mokeyjay.com" style="width:240px; height:380px; border: 0"></iframe>
```

Taking `WordPress` as an example. On `wp-admin`, click on **Appearance** -> **Widgets**
Expand All @@ -29,13 +29,13 @@ Then add a **Text** or **Custom HTML** widget as deemed appropriate on the right
Wanted to customize the code yourself? Thought the service I provided is slow in speed?

You can also easily deploy your own widget!
> Requires PHP version >= 5.6
> Requires Docker or PHP version >= 5.6
[Deployment Documentation](https://github.com/mokeyjay/Pixiv-daily-ranking-widget/blob/master/doc/deploy.en.md)

## 🔌 APIs
[Ranking data (images hosted privately)](https://cloud.mokeyjay.com/pixiv/?r=api/pixiv-json) (recommended)
[Ranking data (pixiv url)](https://cloud.mokeyjay.com/pixiv/?r=api/source-json)
[Ranking data (images hosted privately)](https://pixiv.mokeyjay.com/?r=api/pixiv-json) (recommended)
[Ranking data (pixiv url)](https://pixiv.mokeyjay.com/?r=api/source-json)

In which `data` is the data of the ranking table; `date` is the date of ranking (could be yesterday or the day before, as the time of refresh on Pixiv is not certain)

Expand All @@ -44,33 +44,32 @@ Both APIs automatically return the respective cross-domain header according to `
> The `image` and `url` keys are for compatibility purposes for users of 4.x or earlier versions, they can be ignored
## 🆙 Upgrading Guide
### Upgrading From 5.1 to 5.2
### Upgrading From 5.2 to 6.0
1. [Download the Source Code](https://github.com/mokeyjay/pixiv-daily-ranking-widget/releases/latest)
2. Unzip and overwrite the `app` and `index.php` to on your server
3This version adds a new config item `header_script`, so you can customize statistics code or js script

### Upgrading From 4.x to 5.x
1. Check the code comment of `image_hosting` item in [config.php](https://github.com/mokeyjay/Pixiv-daily-ranking-widget/blob/master/config.php#L88), select the most suitable image hosting option and fill it in your `config.php`
2. Delete all files in `storage/app` to enable the application refreshing the ranking data
2. Unzip and overwrite the `app` and `index.php` to your server
> **⚠️ For Docker User**
> - Please replace all `-` in the environment variable name with `_`
> - Docker Image migration from Docker Hub to [ghcr.io](https://github.com/mokeyjay/Pixiv-daily-ranking-widget/pkgs/container/pixiv-daily-ranking-widget)
## 🌟 Changelog
### New Features
- Support Docker (thanks to @hujingnb)
- `header_script` configuration item, so you can customize statistics code or js script
- Added `ranking_type` configuration option, which now allows you to select whether to fetch the overall or illustration/manga daily rankings.
- Added image preloading to improve the experience in poor network environments.
### Optimizations
- Used the proxy service provided by pixiv.cat as a final guarantee plan
- Riyugo image hosting changed to vip version, you need to buy a vip account before use it (free version is no longer available)
- Improve image download integrity check mechanism
- Removed built-in statistics code
- Completely rewritten the frontend with more elegant animation effects.
- Removed the dependency on Bootstrap for faster loading.
- Switched to using the official PHP and Nginx packages.
- No longer repeatedly check integrity when retrieving images from local storage.
### Fixes
- Some environment variables cannot be obtained normally in some cases
- The scheduled task actually runs once every hour, not every half hour as stated in the documentation
### Other
- Removed invalid JD, imgurl, imgtg and saoren image hosting
- Removed the `static_cdn` configuration option due to the removal of the dependency on Bootstrap.
- Removed the invalid `Pngcm` and `Tsesze` image-hosting
- Docker image migration to [ghcr.io](https://github.com/mokeyjay/Pixiv-daily-ranking-widget/pkgs/container/pixiv-daily-ranking-widget)
- Docker image timezone defaults to Shanghai

[History](https://github.com/mokeyjay/Pixiv-daily-ranking-widget/blob/master/doc/log.en.md)

## 💖 Special Sponsor
Many thanks to Jetbrains for providing me with an open source license for the IDE to complete development on this and other open source projects.

[![](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/?from=https://github.com/mokeyjay)

## 👨‍💻 About author
[mokeyjay](https://www.mokeyjay.com), IT and ACG lover
Loading

0 comments on commit 88ce973

Please sign in to comment.