From fa7b27a8781d480a214274d3e515448efceb63eb Mon Sep 17 00:00:00 2001 From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com> Date: Thu, 13 May 2021 13:59:36 +0800 Subject: [PATCH] try fix GBK txt preview --- disk/Onedrive.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/disk/Onedrive.php b/disk/Onedrive.php index d854886..cdd7211 100644 --- a/disk/Onedrive.php +++ b/disk/Onedrive.php @@ -100,11 +100,23 @@ class Onedrive { } } if (isset($files['file'])) { - if (in_array(splitlast($files['name'],'.')[1], $exts['txt'])) { - if (!(isset($files['content'])&&$files['content']['stat']==200)) { - $content1 = curl('GET', $files[$this->DownurlStrName]); - $files['content'] = $content1; - savecache('path_' . $path, $files, $this->disktag); + if (in_array(strtolower(splitlast($files['name'],'.')[1]), $exts['txt'])) { + if ($files['size']<1024*1024) { + if (!(isset($files['content'])&&$files['content']['stat']==200)) { + $content1 = curl('GET', $files[$this->DownurlStrName]); + $tmp = null; + $tmp = json_decode(json_encode($content1), true); + if ($tmp['body']===null) { + $tmp['body'] = iconv("GBK", 'UTF-8//TRANSLIT', $content1['body']); + $tmp = json_decode(json_encode($tmp), true); + if ($tmp['body']!==null) $content1['body'] = $tmp['body']; + } + $files['content'] = $content1; + savecache('path_' . $path, $files, $this->disktag); + } + } else { + $files['content']['stat'] = 202; + $files['content']['body'] = 'File too large.'; } } }