Skip to content

Commit

Permalink
Photopea: bump 1.1, show unwritable when no write permission
Browse files Browse the repository at this point in the history
  • Loading branch information
zhtengw committed Apr 27, 2020
1 parent 50e4638 commit 919c55f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
36 changes: 23 additions & 13 deletions kodbox-plugins/Photopea/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ public function index() {
$fileExt = get_path_ext($this->fileInfo['name']);

$fileUrl = $this->filePathLinkOut($this->in['path']).'&name=/'.$fileName;
$saveUrl = $this->pluginApi.'saveImg&cache='.rawurlencode($localFile).'&path='.rawurlencode($path);

//可写权限检测
$saveUrl = $this->pluginApi.'saveImg&unwritable=1';
if (Action("explorer.auth")->fileCanWrite($path)) {
$saveUrl = $this->pluginApi.'saveImg&cache='.rawurlencode($localFile).'&path='.rawurlencode($path);
}

$fullUri = '{"files":["'.$fileUrl.'"],"resources":[],"server":{"version":1,"url":"'.$saveUrl.'","formats":["'.$fileExt.'"]},"environment":{},"script":""}';

$config = $this->getConfig();
Expand All @@ -29,18 +35,22 @@ public function index() {

}
public function saveImg() {
header('Content-type: application/json; charset="utf-8"');
if (isset($_GET['unwritable'])) {
echo '{"message": "Unwritable!"}';
} else {
header('Content-type: application/json; charset="utf-8"');

$fi = fopen("php://input", "rb");
$p = JSON_decode(fread($fi, 2000));
$fo = fopen($_GET['cache'],"wb");
while ($buf = fread($fi,50000)) {
fwrite($fo,$buf);
$fi = fopen("php://input", "rb");
$p = JSON_decode(fread($fi, 2000));
$fo = fopen($_GET['cache'],"wb");
while ($buf = fread($fi,50000)) {
fwrite($fo,$buf);
}
fclose($fi);
fclose($fo);
$this->pluginCacheFileSet($_GET['path'], file_get_contents($_GET['cache']));
del_file($_GET['cache']);
echo '{"message": "Saved!"}';
}
fclose($fi);
fclose($fo);
$this->pluginCacheFileSet($_GET['path'], file_get_contents($_GET['cache']));
del_file($_GET['cache']);
echo '{"message": "Saved!"}';
}
}
}
2 changes: 1 addition & 1 deletion kodbox-plugins/Photopea/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id":"Photopea",
"name":"{{LNG['Photopea.meta.name']}}",
"title":"{{LNG['Photopea.meta.title']}}",
"version":"1.0.3",
"version":"1.1",
"category":"file",
"source":{
"icon":"{{pluginHost}}static/images/icon.png",
Expand Down
8 changes: 7 additions & 1 deletion kodexplorer-plugins/Photopea/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ public function index() {
$fileName = get_path_this(rawurldecode($this->in['path']));
$fileExt = get_path_ext($path);
$fileUrl = $this->pluginHost.'php/handler.php?act=sent&path='.rawurlencode($path);
$saveUrl = $this->pluginHost.'php/handler.php?act=save&path='.rawurlencode($path);

//可写权限检测
$saveUrl = $this->pluginHost.'php/handler.php?act=unwritable';
if (check_file_writable_user($path)) {
$saveUrl = $this->pluginHost.'php/handler.php?act=save&path='.rawurlencode($path);
}

$fullUri = '{"files":["'.$fileUrl.'"],"resources":[],"server":{"version":1,"url":"'.$saveUrl.'","formats":["'.$fileExt.'"]},"environment":{},"script":""}';

$config = $this->getConfig();
Expand Down
2 changes: 1 addition & 1 deletion kodexplorer-plugins/Photopea/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id":"Photopea",
"name":"{{LNG.Photopea.meta.name}}",
"title":"{{LNG.Photopea.meta.title}}",
"version":"1.0.3",
"version":"1.1",
"category":"file",
"source":{
"icon":"{{pluginHost}}static/images/icon.png",
Expand Down
3 changes: 3 additions & 0 deletions kodexplorer-plugins/Photopea/php/handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
if ($action == 'sent') {
fileStream();
}
if ($action == 'unwritable'){
echo '{"message": "Unwritable!"}';
}

function saveImg() {
header('Content-type: application/json; charset="utf-8"');
Expand Down

0 comments on commit 919c55f

Please sign in to comment.