try fix GBK txt preview

pull/321/head
qkqpttgf 2021-05-13 13:58:43 +08:00 committed by GitHub
parent 741044e5ea
commit 279055b3bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 15 deletions

View File

@ -128,21 +128,33 @@ class Googledrive {
//$this->permission('delete', $files['id']); //$this->permission('delete', $files['id']);
//if (isset($item['mimeType']) && $item['mimeType']!='application/vnd.google-apps.folder') { //if (isset($item['mimeType']) && $item['mimeType']!='application/vnd.google-apps.folder') {
if (in_array(splitlast($item['name'],'.')[1], $exts['txt'])) { if (in_array(strtolower(splitlast($item['name'],'.')[1]), $exts['txt'])) {
if (!(isset($item['content'])&&$item['content']['stat']==200)) { if ($files['size']<1024*1024) {
//if (!isset($item['downUrl'])) { if (!(isset($item['content'])&&$item['content']['stat']==200)) {
$res = curl('GET', $item['webContentLink'], '', [], 1); //if (!isset($item['downUrl'])) {
$weblink = $res['returnhead']['Location']; $res = curl('GET', $item['webContentLink'], '', [], 1);
//if ($weblink!==null) $item['downUrl'] = $weblink; $weblink = $res['returnhead']['Location'];
//else error_log1('Cant get link:' . json_encode($res, JSON_PRETTY_PRINT)); //if ($weblink!==null) $item['downUrl'] = $weblink;
//} //else error_log1('Cant get link:' . json_encode($res, JSON_PRETTY_PRINT));
if ($res['stat']==302) { //}
$content1 = curl('GET', $weblink, '', ["User-Agent"=>"qkqpttgf/OneManager 3.0.0", "Accept"=>"*/*"]); if ($res['stat']==302) {
$item['content'] = $content1; $content1 = curl('GET', $weblink, '', ["User-Agent"=>"qkqpttgf/OneManager 3.0.0", "Accept"=>"*/*"]);
}// else $content1 = $res; $tmp = null;
//error_log1($item['name'] . '~' . json_encode($content1, JSON_PRETTY_PRINT) . PHP_EOL); $tmp = json_decode(json_encode($content1), true);
$parent_folder['files'][$i] = $item; if ($tmp['body']===null) {
savecache('path_' . $path, $parent_folder, $this->disktag); $tmp['body'] = iconv("GBK", 'UTF-8//TRANSLIT', $content1['body']);
$tmp = json_decode(json_encode($tmp), true);
if ($tmp['body']!==null) $content1['body'] = $tmp['body'];
}
$item['content'] = $content1;
}// else $content1 = $res;
//error_log1($item['name'] . '~' . json_encode($content1, JSON_PRETTY_PRINT) . PHP_EOL);
$parent_folder['files'][$i] = $item;
savecache('path_' . $path, $parent_folder, $this->disktag);
}
} else {
$files['content']['stat'] = 202;
$files['content']['body'] = 'File too large.';
} }
} }
//} //}