From 89c311c410dab58cbd5442bb4b08e446f6871045 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Fri, 31 Jan 2020 13:50:09 +0800 Subject: [PATCH] fix(github): binary files related: #21 --- lib/screens/object.dart | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/screens/object.dart b/lib/screens/object.dart index 7886093..9ff8785 100644 --- a/lib/screens/object.dart +++ b/lib/screens/object.dart @@ -74,11 +74,23 @@ class ObjectScreen extends StatelessWidget { return ObjectTree( items: (data as GhObjectTree).entries.map((v) { // if (item.type == 'commit') return null; + String url; + var ext = p.extension(v.name); + if (ext.startsWith('.')) ext = ext.substring(1); + if (['pdf', 'docx', 'doc', 'pptx', 'ppt', 'xlsx', 'xls'] + .contains(ext)) { + // Let system browser handle these files + url = + 'https://raw.githubusercontent.com/$owner/$name/$branch/$path'; + } else { + url = + '/$owner/$name/blob/$branch?path=${p.join(_pathNotNull, v.name).urlencode}'; + } + return ObjectTreeItem( name: v.name, type: v.type, - url: - '/$owner/$name/blob/$branch?path=${p.join(_pathNotNull, v.name).urlencode}', + url: url, size: v.object.resolveType == 'Blob' ? (v.object as GhObjectBlob).byteSize : null,