diff --git a/inc/api.php b/inc/api.php index 5e2dfe0..1f2fcbd 100644 --- a/inc/api.php +++ b/inc/api.php @@ -21,7 +21,7 @@ add_action('rest_api_init', function () { 'callback' => 'feature_gallery', )); register_rest_route('sakura/v1', '/database/update', array( - 'methods' => 'POST', + 'methods' => 'GET', 'callback' => 'update_database', )); register_rest_route('sakura/v1', '/qqinfo/json', array( @@ -367,48 +367,30 @@ function feature_gallery() { * @rest api接口路径:https://sakura.2heng.xin/wp-json/sakura/v1/database/update */ function update_database() { - $username = $_SERVER['PHP_AUTH_USER']; - $password = $_SERVER['PHP_AUTH_PW']; - $user = wp_authenticate($username, $password); - if (is_a($user, 'WP_User')) { - if (in_array('administrator', (array) $user->roles)) { - global $wpdb; - $sakura_table_name = $wpdb->base_prefix.'sakura'; - if(isset($_FILES["manifest"])) { - $manifest = array( - "key" => "manifest_json", - "value" => file_get_contents($_FILES["manifest"]["tmp_name"]) - ); - $time = array( - "key" => "json_time", - "value" => date("Y-m-d H:i:s",time()) - ); - - $wpdb->query("DELETE FROM `wp_sakura` WHERE `mate_key` ='manifest_json'"); - $wpdb->query("DELETE FROM `wp_sakura` WHERE `mate_key` ='json_time'"); - $wpdb->insert($sakura_table_name,$manifest); - $wpdb->insert($sakura_table_name,$time); - $message = "manifest.json has been stored into database."; - } - $output = array( - 'status' => 200, - 'success' => true, - 'message' => $message - ); - $result = new WP_REST_Response($output, 200); - $result->set_headers(array('Content-Type' => 'application/json')); - return $result; - } - } else { - $output = array( - 'status' => 401, - 'success' => false, - 'message' => 'Not Authorized.' + global $wpdb; + $sakura_table_name = $wpdb->base_prefix.'sakura'; + $img_domain = akina_option('cover_cdn') ? akina_option('cover_cdn') : get_template_directory_uri(); + $manifest = file_get_contents($img_domain . "/manifest/manifest.json"); + if($manifest) { + $manifest = array( + "key" => "manifest_json", + "value" => $manifest ); - $result = new WP_REST_Response($output, 401); - $result->set_headers(array('Content-Type' => 'application/json')); - return $result; + $time = array( + "key" => "json_time", + "value" => date("Y-m-d H:i:s",time()) + ); + + $wpdb->query("DELETE FROM `wp_sakura` WHERE `mate_key` ='manifest_json'"); + $wpdb->query("DELETE FROM `wp_sakura` WHERE `mate_key` ='json_time'"); + $wpdb->insert($sakura_table_name,$manifest); + $wpdb->insert($sakura_table_name,$time); + $output = "manifest.json has been stored into database."; + }else{ + $output = "manifest.json not found, please ensure your url is corrent."; } + $result = new WP_REST_Response($output, 200); + return $result; } /** diff --git a/languages/en_US.mo b/languages/en_US.mo index b6bb5a7..b9992f7 100644 Binary files a/languages/en_US.mo and b/languages/en_US.mo differ diff --git a/languages/en_US.po b/languages/en_US.po index 090a9c3..532c211 100644 --- a/languages/en_US.po +++ b/languages/en_US.po @@ -1,8 +1,8 @@ msgid "" msgstr "" "Project-Id-Version: Sakura\n" -"POT-Creation-Date: 2019-12-13 14:51+0800\n" -"PO-Revision-Date: 2019-12-13 14:51+0800\n" +"POT-Creation-Date: 2019-12-15 14:40+0800\n" +"PO-Revision-Date: 2019-12-15 14:40+0800\n" "Last-Translator: \n" "Language-Team: \n" "Language: en_US\n" @@ -1307,11 +1307,12 @@ msgid "Cover CDN" msgstr "" #: options.php:880 +#, php-format msgid "" "Fill in the cdn path for random picture display, without adding a slash at " "the end, for example: https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3, " "please refer to Wiki " +"\">Wiki . Click here to update manifest" msgstr "" #: options.php:886 diff --git a/languages/sakura.pot b/languages/sakura.pot index 7787ef0..b9320ef 100644 --- a/languages/sakura.pot +++ b/languages/sakura.pot @@ -3,7 +3,7 @@ msgid "" msgstr "" "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" "Project-Id-Version: Sakura\n" -"POT-Creation-Date: 2019-12-13 14:50+0800\n" +"POT-Creation-Date: 2019-12-15 14:40+0800\n" "PO-Revision-Date: 2019-11-01 14:27+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -1291,10 +1291,12 @@ msgid "Cover CDN" msgstr "" #: options.php:880 +#, php-format msgid "" "Fill in the cdn path for random picture display, without adding a slash at the end, for " "example: https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3, please refer to Wiki " +"\"https: //github.com/mashirozx/Sakura/wiki/options\">Wiki . Click here to update manifest" msgstr "" #: options.php:886 diff --git a/languages/zh_CN.mo b/languages/zh_CN.mo index b42f935..f4480f5 100644 Binary files a/languages/zh_CN.mo and b/languages/zh_CN.mo differ diff --git a/languages/zh_CN.po b/languages/zh_CN.po index 162f250..9fd26c6 100644 --- a/languages/zh_CN.po +++ b/languages/zh_CN.po @@ -1,8 +1,8 @@ msgid "" msgstr "" "Project-Id-Version: Sakura\n" -"POT-Creation-Date: 2019-12-13 14:51+0800\n" -"PO-Revision-Date: 2019-12-13 14:51+0800\n" +"POT-Creation-Date: 2019-12-15 14:41+0800\n" +"PO-Revision-Date: 2019-12-15 14:41+0800\n" "Last-Translator: \n" "Language-Team: \n" "Language: zh_CN\n" @@ -1328,15 +1328,23 @@ msgid "Cover CDN" msgstr "封面图图片库" #: options.php:880 +#, fuzzy, php-format +#| msgid "" +#| "Fill in the cdn path for random picture display, without adding a slash " +#| "at the end, for example: https://cdn.jsdelivr.net/gh/mashirozx/" +#| "sakura@3.3.3, please refer to Wiki . Click here to update " +#| "manifest" msgid "" "Fill in the cdn path for random picture display, without adding a slash at " "the end, for example: https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3, " "please refer to Wiki " +"\">Wiki . Click here to update manifest" msgstr "" "填写 cdn 路径,用于随机图片展示,最后不用加斜杠,例:https://cdn.jsdelivr." "net/gh/mashirozx/sakura@3.3.3 ,更多信息请参考Wiki" +"mashirozx/Sakura/wiki/options\">Wiki。点击这里更新" +"manifest" #: options.php:886 msgid "Use the front-end library locally (lib.js、lib.css)" diff --git a/manifest/README.md b/manifest/README.md index 10c0fab..c34eb2b 100644 --- a/manifest/README.md +++ b/manifest/README.md @@ -24,8 +24,6 @@ pip3 install Pillow pip install Pillow --user ``` -用同样的方法安装`requests` - ### 运行 把图片文件放到 `gallary` 目录,Windows 可直接双击 manifest.py,或者和其他操作系统一样,在 Terminal、Powershell、CMD 中运行: diff --git a/manifest/manifest.py b/manifest/manifest.py index 9828390..0e7421c 100644 --- a/manifest/manifest.py +++ b/manifest/manifest.py @@ -7,8 +7,6 @@ Desc: Webp convertor import os import sys import json -import requests -import base64 import hashlib from PIL import Image @@ -50,29 +48,6 @@ class Single(object): self.manifest() return self.mani - -class Upload2Wordpress(object): - def __init__(self, username, password, url): - self.username = username - self.password = password - self.url = url - - def upload(self, file, field): - data_string = self.username + ':' + self.password - token = base64.b64encode(data_string.encode()).decode('utf-8') - headers = { - 'Authorization': 'Basic ' + token, - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97" - } - files = {field: open(file, mode="rb")} - reply = requests.post(self.url, headers=headers, files=files) - print(json.loads(reply.content)['message']) - - def main(self): - print('start uploading `manifest.json`...') - self.upload('manifest.json', 'manifest') - - def gen_manifest_json(): onlyfiles = [f for f in os.listdir('gallary') if os.path.isfile(os.path.join('gallary', f))] id = 1 @@ -88,11 +63,6 @@ def gen_manifest_json(): def main(): gen_manifest_json() - username = input('Enter your username: ') - password = input('Enter your password: ') - url = input('Enter your rest api url: ') - upload = Upload2Wordpress(username, password, url) - upload.main() if __name__ == '__main__': diff --git a/options.php b/options.php index 6df04e3..4d61858 100644 --- a/options.php +++ b/options.php @@ -877,7 +877,7 @@ function optionsframework_options() { $options[] = array( 'name' => __('Cover CDN', 'sakura'),/*封面图片库*/ - 'desc' => __('Fill in the cdn path for random picture display, without adding a slash at the end, for example: https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3, please refer to Wiki ', 'sakura'),/*填写 cdn 路径,用于随机图片展示,最后不用加斜杠,例:https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3 ,更多信息请参考Wiki*/ + 'desc' => sprintf(__('Fill in the cdn path for random picture display, without adding a slash at the end, for example: https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3, please refer to Wiki . Click here to update manifest', 'sakura'), rest_url('sakura/v1/database/update')),/*填写 cdn 路径,用于随机图片展示,最后不用加斜杠,例:https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3 ,更多信息请参考Wiki*/ 'id' => 'cover_cdn', 'std' => 'https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3', 'type' => 'text');