diff --git a/README.en.md b/README.en.md index 605fbbd..bfdd334 100644 --- a/README.en.md +++ b/README.en.md @@ -44,32 +44,24 @@ 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.0 to 5.1 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 +3. This version adds a new image-hosting, you can modify the `image_hosting` configuration in `config.php` as you needed -### Upgrading From 4.x to 5.0 -1. Check the code comment of `image_hosting` item in [config.php](config.php#L90), select the most suitable image hosting option and fill it in your `config.php` +### Upgrading From 4.x to 5.x +1. Check the code comment of `image_hosting` item in [config.php](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 ## 🌟 Changelog ### New Features -- Supporting cross-domain on the APIs -- Scheduled job to clear historical logs -- Supporting 8 free image hosts +- JD, Riyugo, FiftyEight image hosting +- `static_cdn` configuration, you can choose the front-end static resource CDN provider ### Optimizations -- Picture display effect -- Left and right arrows will now be hidden automatically -- Display arwork title and author on mouse hover -- Upgrade front-end dependency packages to their latest while reducing amount of dependencies -- Improved logging function -- Enrich interface data to fit more use cases -- Replace Baidu Analytics with Google Analytics -- Update default User Agent -### Fixes -- Project URL cannot be retrieved correctly under certain scenarios -- A blank image will be downloaded under certain scenarios +- Rewritten left and right arrows, fixed some issues with it ### Other -- Removed the invalid Alibaba image hosting option +- Removed the invalid Baidu, Imgstop image hosting option +- Replace Google Analytics with Baidu Analytics [History](doc/log.en.md) diff --git a/README.md b/README.md index 6cba587..c347b64 100644 --- a/README.md +++ b/README.md @@ -42,32 +42,24 @@ > `image` 和 `url` 两个键是为了兼容 4.x 及之前版本的用户,无需理会 ## 🆙 升级指南 +### 从 5.0 升级到 5.1 1. [下载源代码](https://github.com/mokeyjay/Pixiv-daily-ranking-widget/releases/latest) 2. 解压缩,将其中的 `app` 和 `index.php` 覆盖到线上环境 +3. 此版本添加了新的图床,你可以按需修改 `config.php` 中的 `image_hosting` 配置项 -### 从 4.x 升级到 5.0 -1. 查看 [config.php](config.php#L90) 中 `image_hosting` 配置项的注释说明,选择适合你的图床配置,填写到你线上环境的 `config.php` 中 +### 从 4.x 升级到 5.x +1. 查看 [config.php](config.php#L88) 中 `image_hosting` 配置项的注释说明,选择适合你的图床配置,填写到你线上环境的 `config.php` 中 2. 删除 `storage/app` 下的所有文件,让程序重新获取排行榜数据 ## 🌟 更新日志 ### 新增 -- 支持跨域请求的数据接口 -- clear-log 任务用于清除历史日志文件 -- 共计 8 个国内外公开、免费的图床 +- 京东、薄荷、58图床 +- `static_cdn` 配置项,可以选择前端静态资源 CDN 供应商 ### 优化 -- 图片显示效果 -- 左右翻页箭头现在会自动隐藏了 -- 鼠标悬浮时显示作品标题及作者名称 -- 升级前端依赖包至最新、减少依赖 -- 完善日志记录功能 -- 丰富接口数据以适应更多场景 -- 将百度统计更换为谷歌统计 -- 更新默认 UA -### 修复 -- 部分情况下无法正确获取项目 url 的问题 -- 部分情况下可能会下载到空白图片的问题 +- 重写了左右翻页箭头,修复了它的一些问题 ### 其他 -- 去掉失效的阿里巴巴图床 +- 去掉失效的百度、映画图床 +- 将谷歌分析更换为百度统计 [历史更新日志](doc/log.md) diff --git a/app/ImageHosting/Baidu.php b/app/ImageHosting/Baidu.php deleted file mode 100644 index c013a8b..0000000 --- a/app/ImageHosting/Baidu.php +++ /dev/null @@ -1,45 +0,0 @@ - Curl::getCurlFile($path), - 'no_compress' => '1', - 'id' => 'WU_FILE_0', - 'is_avatar' => '0', - 'type' => 'image', - 'name' => pathinfo($path, PATHINFO_FILENAME) . '.jpg' - ]; - $result = Curl::post('https://baijiahao.baidu.com/builderinner/api/content/file/upload', $data, [ - CURLOPT_HTTPHEADER => [ - 'Origin: https://baijiahao.baidu.com', - 'Referer: https://baijiahao.baidu.com/builder/app/register?type=individual' - ], - ]); - - Log::write('[百度图床]上传:' . json_encode($data)); - Log::write('[百度图床]返回:' . $result); - - $json = json_decode($result, true); - if(isset($json['errno']) && $json['errno'] == 0 && isset($json['ret']['org_url'])){ - return $json['ret']['org_url']; - } - - Log::write('[百度图床]上传失败', 'ERROR'); - return false; - } -} \ No newline at end of file diff --git a/app/ImageHosting/FiftyEight.php b/app/ImageHosting/FiftyEight.php new file mode 100644 index 0000000..bd31d9a --- /dev/null +++ b/app/ImageHosting/FiftyEight.php @@ -0,0 +1,42 @@ + '0*0', + 'Pic-Encoding' => 'base64', + 'Pic-Path' => '/nowater/webim/big/', + 'Pic-Data' => base64_encode(file_get_contents($path)), + ]; + $result = Curl::post('https://upload.58cdn.com.cn/json', json_encode($data), [ + CURLOPT_HTTPHEADER => [ + 'Origin: https://ai.58.com', + 'Referer: https://ai.58.com/pc/' + ], + ]); + + $data['Pic-Data'] = '(数据长度:' . strlen($data['Pic-Data']) . ')'; + Log::write('[58图床]上传:' . json_encode($data)); + Log::write('[58图床]返回:' . $result); + + if (empty($result) || stripos($result, 'n_v2') !== 0) { + Log::write('[58图床]上传失败', 'ERROR'); + return false; + } + + return 'https://pic3.58cdn.com.cn/nowater/webim/big/' . $result; + } +} \ No newline at end of file diff --git a/app/ImageHosting/Imgstop.php b/app/ImageHosting/Imgstop.php deleted file mode 100644 index 4743ed8..0000000 --- a/app/ImageHosting/Imgstop.php +++ /dev/null @@ -1,51 +0,0 @@ - Curl::getCurlFile($path), - // 7=携程 15=易车,随机选一个 - 'strategy_id' => [7, 15][mt_rand(0, 1)], - ]; - $opt = [ - CURLOPT_HTTPHEADER => [ - 'x-csrf-token: ' . $csrfToken, - ], - CURLOPT_COOKIE => $result['cookie'], - ]; - $result = Curl::post('https://imgs.top/upload', $data, $opt); - - Log::write('[映画の图床]上传:' . json_encode(compact('data', 'opt'))); - Log::write('[映画の图床]返回:' . $result); - - $json = json_decode($result, true); - if (!empty($json['data']['imgurl'])) { - return $json['data']['imgurl']; - } - - Log::write('[映画の图床]上传失败', 'ERROR'); - return false; - } -} \ No newline at end of file diff --git a/app/ImageHosting/Jd.php b/app/ImageHosting/Jd.php new file mode 100644 index 0000000..b174b71 --- /dev/null +++ b/app/ImageHosting/Jd.php @@ -0,0 +1,46 @@ + 'im.customer', + 'aid' => 'undefined', + 'clientType' => 'comet', + 'pin' => 'undefined', + 's' => 'data:image/jpg;base64,' . base64_encode(file_get_contents($path)), + ]; + $result = Curl::post('https://imio.jd.com/uploadfile/file/post.do', $data, [ + CURLOPT_HTTPHEADER => [ + 'accept: application/json, text/plain, */*', + 'referer: https://jdcs.jd.com/jdchat/custom.action?entry=jd_fwztc', + 'origin: https://jdcs.jd.com', + 'Upgrade-insecure-requests: 1', + ], + ]); + + $data['s'] = '(数据长度:' . strlen($data['s']) . ')'; + Log::write('[京东]上传:' . json_encode($data)); + Log::write('[京东]返回:' . $result); + + preg_match_all('|https://(.*?)"|', $result, $result); + if (!empty($result[1][0])) { + return "https://{$result[1][0]}"; + } + + Log::write('[京东]上传失败', 'ERROR'); + return false; + } +} \ No newline at end of file diff --git a/app/ImageHosting/Riyugo.php b/app/ImageHosting/Riyugo.php new file mode 100644 index 0000000..4685ca1 --- /dev/null +++ b/app/ImageHosting/Riyugo.php @@ -0,0 +1,44 @@ + pathinfo($path, PATHINFO_BASENAME), + 'uuid' => 'o_1gbng' . Str::random(22), + 'nameMode' => 'isRenameMode', + 'file' => Curl::getCurlFile($path), + ]; + $result = Curl::post('https://4ae.cn/localup.php', $data, [ + CURLOPT_HTTPHEADER => [ + 'accept: */*', + 'referer: https://riyugo.com/', + 'origin: https://riyugo.com', + ], + ]); + + Log::write('[薄荷图床]上传:' . json_encode($data)); + Log::write('[薄荷图床]返回:' . $result); + + $json = json_decode($result, true); + if (isset($json['result']) && $json['result'] == 'success' && !empty($json['url'])) { + return $json['url']; + } + + Log::write('[薄荷图床]上传失败', 'ERROR'); + return false; + } +} \ No newline at end of file diff --git a/app/ImageHosting/Saoren.php b/app/ImageHosting/Saoren.php index f647a6c..0d71e5c 100644 --- a/app/ImageHosting/Saoren.php +++ b/app/ImageHosting/Saoren.php @@ -7,7 +7,7 @@ use app\Libs\Str; /** - * 骚人图床(国内) + * 骚人图床(国内,有鉴黄,偶尔会有图 404) * Class Saoren * @package app\ImageHosting * @url https://tu.sao.ren/ diff --git a/app/Libs/Config.php b/app/Libs/Config.php index 0fcae11..b11d5b5 100644 --- a/app/Libs/Config.php +++ b/app/Libs/Config.php @@ -21,6 +21,8 @@ class Config public static $image_hosting = ['local']; public static $image_hosting_extend = []; public static $disable_web_job = false; + public static $static_cdn = 'bytedance'; + public static $static_cdn_url = []; /** * 初始化配置 @@ -33,12 +35,12 @@ public static function init() self::$$key = $value; } - // 获取本项目url + // 获取本项目 url if (self::$url == '' && !IS_CLI) { self::$url = Request::getCurrentUrl(); } - // 是否对外提供服务,是则获取url参数 + // 是否对外提供服务,是则获取 url 参数 if (self::$service) { if (isset($_GET['color'])) { self::$background_color = '#' . $_GET['color']; @@ -48,6 +50,8 @@ public static function init() } } + self::initStaticCdnUrl(self::$static_cdn); + try { if (!is_writable(STORAGE_PATH)) { throw new \Exception(STORAGE_PATH . ' 目录无法写入'); @@ -72,4 +76,41 @@ public static function init() die; } } + + /** + * 初始化静态资源 CDN + * @param $provider + * @return void + */ + private static function initStaticCdnUrl($provider) + { + $url = [ + 'bootcdn' => [ + 'bootstrap-css' => 'https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.0/css/bootstrap.min.css', + 'bootstrap-js' => 'https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.0/js/bootstrap.min.js', + ], + 'baomitu' => [ + 'bootstrap-css' => 'https://lib.baomitu.com/twitter-bootstrap/5.2.0/css/bootstrap.min.css', + 'bootstrap-js' => 'https://lib.baomitu.com/twitter-bootstrap/5.2.0/js/bootstrap.bundle.min.js', + ], + 'bytedance' => [ + 'bootstrap-css' => 'https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/bootstrap/5.1.3/css/bootstrap.min.css', + 'bootstrap-js' => 'https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/bootstrap/5.1.3/js/bootstrap.min.js', + ], + 'cdnjs' => [ + 'bootstrap-css' => 'https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.2.0/css/bootstrap.min.css', + 'bootstrap-js' => 'https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.2.0/js/bootstrap.min.js', + ], + 'jsdelivr' => [ + 'bootstrap-css' => 'https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css', + 'bootstrap-js' => 'https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.min.js', + ], + ]; + + if (!isset($url[$provider])) { + $provider = 'bytedance'; + } + + self::$static_cdn_url = $url[$provider]; + } } \ No newline at end of file diff --git a/app/Libs/Curl.php b/app/Libs/Curl.php index 49db94b..856e5c0 100644 --- a/app/Libs/Curl.php +++ b/app/Libs/Curl.php @@ -24,7 +24,7 @@ public static function get($url, $opt = [], $includeCookie = false) curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); - curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36 Edg/103.0.1264.49'); + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36 Edg/104.0.1293.70'); Config::$proxy && curl_setopt($ch, CURLOPT_PROXY, Config::$proxy); $includeCookie && curl_setopt($ch, CURLOPT_HEADER, true); diff --git a/app/Views/index.php b/app/Views/index.php index 3571503..0539f5f 100644 --- a/app/Views/index.php +++ b/app/Views/index.php @@ -10,9 +10,10 @@ + Pixiv 每日排行榜 Top<?=Config::$limit?> 小挂件 - + - - @@ -130,20 +123,18 @@ function gtag(){dataLayer.push(arguments);}
- + \ No newline at end of file diff --git a/config.php b/config.php index 923088e..76b1e09 100644 --- a/config.php +++ b/config.php @@ -85,7 +85,7 @@ * * It is recommended to fill in more than one image-hosting, if one of them fails to upload, it will continue to try other image-hosting in order */ - 'image_hosting' => ['baidu', 'imgstop', 'saoren', 'tsesze', 'imgtg', 'chkaja', 'pngcm', 'catbox', 'imgurl', 'local'], + 'image_hosting' => ['jd', 'riyugo', 'fifty-eight', 'saoren', 'tsesze', 'imgtg', 'chkaja', 'pngcm', 'catbox', 'imgurl', 'local'], /** * 图床扩展配置信息 @@ -109,4 +109,13 @@ * See doc/deploy.en.md */ 'disable_web_job' => false, + + /** + * 前端静态资源 CDN 供应商 + * 可选:bytedance, baomitu, bootcdn, cdnjs, jsdelivr + * + * Front-end static resource CDN provider + * Options: jsdelivr, cdnjs, bytedance, baomitu, bootcdn + */ + 'static_cdn' => 'bytedance', ]; \ No newline at end of file diff --git a/doc/log.en.md b/doc/log.en.md index b10e440..00d97ff 100644 --- a/doc/log.en.md +++ b/doc/log.en.md @@ -1,4 +1,24 @@ # History Update Log +### 5.0 +### New Features +- Supporting cross-domain on the APIs +- Scheduled job to clear historical logs +- Supporting 8 free image hosting +### Optimizations +- Picture display effect +- Left and right arrows will now be hidden automatically +- Display arwork title and author on mouse hover +- Upgrade front-end dependency packages to their latest while reducing amount of dependencies +- Improved logging function +- Enrich interface data to fit more use cases +- Replace Baidu Analytics with Google Analytics +- Update default User Agent +### Fixes +- Project URL cannot be retrieved correctly under certain scenarios +- A blank image will be downloaded under certain scenarios +### Other +- Removed the invalid Alibaba image hosting option + ### 4.4.2 - Update default UA of Curl class diff --git a/doc/log.md b/doc/log.md index 36702f7..064bd6d 100644 --- a/doc/log.md +++ b/doc/log.md @@ -1,4 +1,24 @@ # 历史更新日志 +### 5.0 +### 新增 +- 支持跨域请求的数据接口 +- clear-log 任务用于清除历史日志文件 +- 共计 8 个国内外公开、免费的图床 +### 优化 +- 图片显示效果 +- 左右翻页箭头现在会自动隐藏了 +- 鼠标悬浮时显示作品标题及作者名称 +- 升级前端依赖包至最新、减少依赖 +- 完善日志记录功能 +- 丰富接口数据以适应更多场景 +- 将百度统计更换为谷歌统计 +- 更新默认 UA +### 修复 +- 部分情况下无法正确获取项目 url 的问题 +- 部分情况下可能会下载到空白图片的问题 +### 其他 +- 去掉失效的阿里巴巴图床 + ### 4.4.2 - 更新 Curl 类的默认 UA - 删除已经失效的图床 diff --git a/index.php b/index.php index ccfa027..84da966 100644 --- a/index.php +++ b/index.php @@ -1,7 +1,7 @@