Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
fix(View): Fix Conversion::setDefault()
Browse files Browse the repository at this point in the history
1. Fix Conversion::setDefault()
2. Separate ext2Icon to single json file and use ajax to load and cache it
in LocalStorage.

Signed-off-by: Rhilip <rhilipruan@gmail.com>
  • Loading branch information
Rhilip committed Jun 7, 2019
1 parent f3f6206 commit bec2fc0
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 92 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- **Auth:** Fix Broken Auth page after frontend framework change
- **DATABASE:** Fix CURRENT_TIMESTAMP Extra error
- **Error:** Fix Error Handler
- **Invite:** Add Fine-grained control of recycle pending
- **Register:** Add captcha checker
- **Tracker:** Add miss port check for field ipv6_port
- **View:** remove view helper function `get_torrent_uploader_id`
Expand Down
108 changes: 17 additions & 91 deletions apps/public/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,87 +4,6 @@
const api_point = '/api/v1';
const _location_search = new URLSearchParams(window.location.search); // Short and parse location.search

/**
* The icon map for file extension
* Notice: The map key should has the fontawesome icon like `fa-file-${v}`
* Knowledge:
* - file format of 'video','audio' are from MPC-HC : https://mpc-hc.org/
* - file format of 'image' are from arthurvr/image-extensions : https://github.com/arthurvr/image-extensions
* - file format of 'alt' are from sindresorhus/text-extensions: https://github.com/sindresorhus/text-extensions,
* And remove the duplicate element.
* - file format of 'archive are form Wikipedia : https://en.wikipedia.org/wiki/List_of_archive_formats
* - file format of 'word','powerpoint','excel' are from MicroSoft Office 365 ( Word, PowerPoint, Excel )
*/
const ext2Icon = {
video: [
"avi", // AVI
"mpg", "mpeg", "mpe", "m1v", "m2v", "mpv2", "mp2v", "pva", "evo", "m2p", // MPEG
"ts", "tp", "trp", "m2t", "m2ts", "mts", "rec", "ssif", // MPEG-TS
"vob", "ifo", // DVD-Video
"mkv", "mk3d", // Matroska
"webm", // WebM
"mp4", "m4v", "mp4v", "mpv4", "hdmov", // MP4
"mov", // QuickTime-Video
"3gp", "3gpp", "3ga", // #GP
"3g2", "3gp2", // 3G2
"flv", "f4v", // Flash-Video
"ogm", "ogv", // Ogg
"rm", "rmvb", "rt", "ram", "rpm", "rmm", "rp", "smi", "smil", // Real Media with it's script
"wmv", "wmp", "wm", "asf", // Windows Media
"smk", "bik", // Smacker/Bink Video
"fli", "flc", "flic", // FLIC
"dsm", "dsv", "dsa", "dss", // DirectShow
"divx", "amv", // Other
"asx", "m3u", "m3u8", "pls", "wvx", "wax", "wmx", "mpcpl", // Play list
"mpls", "bdmv" // Blu-ray Play list
],
audio: [
"ac3", // AC-3
"dts", "dtshd", "dtsma", // DTS/DTS-HD
"aif", "aifc", "aiff", // AIFF
"alac", // Apple Lossless
"amr", // AMR
"ape", "apl", // Monkey's Audio
"au", "snd", // AU/SND
"cda", // Audio Cd track
"flac", // FLAC
"m4a", "m4b", "m4r", "aac", // MPEG-4 Audio
"mid", "midi", "rmi", // MIDI
"mka", // Matroska
"mp3", // MP3
"mpa", "mp2", "m1a", "m2a", // MPEG Audio
"mpc", // Musepack
"ofr", "ofs", // OptimFROG
"ogg", "oga", // Ogg Vorbis
"opus", // Opus
"ra", // Real Audio
"tak", // TAK
"tta", // True Audio
"wav", // WAV
"wma", // Windows Media Audio
"wv", // WavPack
"aob", "mlp", "thd" // Other
],
image: ["ase","art","bmp","blp","cd5","cit","cpt","cr2","cut","dds","dib","djvu","egt","exif","gif","gpl","grf","icns","ico","iff","jng","jpeg","jpg","jfif","jp2","jps","lbm","max","miff","mng","msp","nitf","ota","pbm","pc1","pc2","pc3","pcf","pcx","pdn","pgm","PI1","PI2","PI3","pict","pct","pnm","pns","ppm","psb","psd","pdd","psp","px","pxm","pxr","qfx","raw","rle","sct","sgi","rgb","int","bw","tga","tiff","tif","vtf","xbm","xcf","xpm","3dv","amf","ai","awg","cgm","cdr","cmx","dxf","e2d","egt","eps","fs","gbr","odg","svg","stl","vrml","x3d","sxd","v2d","vnd","wmf","emf","art","xar","png","webp","jxr","hdp","wdp","cur","ecw","iff","lbm","liff","nrrd","pam","pcx","pgf","sgi","rgb","rgba","bw","int","inta","sid","ras","sun","tga"],
alt: ["ada","adb","ads","applescript","au3","as","asc","ascx","ascii","asm","asmx","asp","aspx","atom","awk","bas","bash","bashrc","bat","bbcolors","bcp","bdsgroup","bdsproj","bib","bowerrc","c","cbl","cc","cfc","cfg","cfm","cfml","cgi","clj","cljs","cls","cmake","cmd","cnf","cob","code-snippets","coffee","coffeekup","conf","cp","cpp","cpy","crt","cs","csh","cson","csproj","csr","css","csslintrc","ctl","curlrc","cxx","d","dart","dfm","diff","dof","dpk","dpr","dproj","dtd","eco","editorconfig","ejs","el","elm","emacs","eml","ent","erb","erl","eslintignore","eslintrc","ex","exs","f03","f77","f90","f95","fish","for","fpp","frm","fsproj","fsx","ftn","gemrc","gemspec","gitattributes","gitconfig","gitignore","gitkeep","gitmodules","go","gpp","gradle","groovy","groupproj","grunit","gtmpl","gvimrc","h","haml","hbs","hgignore","hh","hrl","hpp","hs","hta","htaccess","htc","htm","html","htpasswd","hxx","iced","iml","inc","ini","ino","irbrc","itcl","itermcolors","itk","jade","java","jhtm","jhtml","js","jscsrc","jshintignore","jshintrc","json","json5","jsonld","jsp","jspx","jsx","ksh","less","lhs","lisp","log","ls","lsp","lua","m","m4","mak","map","markdown","master","md","mdown","mdwn","mdx","metadata","mht","mhtml","mjs","mk","mkd","mkdn","mkdown","ml","mli","mm","mxml","nfm","nfo","noon","npmignore","npmrc","nuspec","nvmrc","ops","pas","pasm","patch","pbxproj","pch","pem","pg","php","php3","php4","php5","phpt","phtml","pir","pl","pm","pmc","pod","prettierrc","properties","props","pt","pug","purs","py","pyx","r","rake","rb","rbw","rc","rdoc","rdoc_options","resx","rexx","rhtml","rjs","rlib","ron","rs","rss","rst","rtf","rvmrc","rxml","s","sass","scala","scm","scss","seestyle","sh","shtml","sln","sls","spec","sql","sqlite","sqlproj","ss","sss","st","strings","sty","styl","stylus","sub","sublime-build","sublime-commands","sublime-completions","sublime-keymap","sublime-macro","sublime-menu","sublime-project","sublime-settings","sublime-workspace","sv","svc","swift","t","tcl","tcsh","terminal","tex","text","textile","tg","tk","tmLanguage","tmTheme","tmpl","tpl","tsv","tsx","tt","tt2","ttml","twig","txt","v","vb","vbproj","vbs","vcproj","vcxproj","vh","vhd","vhdl","vim","viminfo","vimrc","vm","vue","webapp","x-php","wsc","xaml","xht","xhtml","xml","xs","xsd","xsl","xslt","y","yaml","yml","zsh","zshrc"],
archive: [
'a', 'ar', 'cpio', 'shar', 'lbr', 'iso', 'mar', 'sbx', 'tar', // Archiving only
'bz2', 'f', 'gz', 'lz', 'lzma', 'lzo', 'rz', 'sfark', 'sz', 'xz', 'z', // Compression only
'7z', 's7z', 'ace', 'afa', 'alz', 'apk', 'arc', 'arj', 'b1', 'b6z', 'ba', 'bh', 'cab', 'car', 'cfs', 'cpt', 'dar', 'dd', 'dgc', 'dmg',
'ear', 'gca', 'ha', 'hki', 'ice', 'jar', 'kgb', 'lzh', 'lha', 'lzx', 'pak', 'partimg', 'paq6', 'paq7', 'paq8', 'pea', 'pim',
'qda', 'rar', 'rk', 'sda', 'sea', 'sen', 'sfx', 'shk', 'sitx', 'sqx', 'tgz', 'tbz2', 'tlz', 'xz', 'txz', 'uc', 'uc0', 'uc2', 'ucn',
'ur2', 'ue2', 'uca', 'war', 'wim', 'xar', 'xp3', 'yz1', 'zip', 'zipx', 'zoo', 'zpaq', 'zz', // Archiving and compression
'ecc', 'ecsbx', 'par', 'par2', 'rev' // Data recovery
],
word: ["doc", "docx", "docm", "dotx", "dotm", "dot", "odt"],
powerpoint: ["ppt", "pptx", "pptm", "potx", "potm", "pot", "ppsx", "ppsm", "pps", "ppam", "ppa", "odp"],
excel: ["xlsx", "xlsm", "xlsb", "xls", "xltx", "xltm", "xlt", "xlam", "xla", "ods"],
pdf: ["pdf"],
csv: ["csv"],
code: [],
contract: []
};

const paswordStrengthText = {
0: "Worst ☹", // too guessable: risky password. (guesses < 10^3)
1: "Bad ☹", // too guessable: risky password. (guesses < 10^3)
Expand Down Expand Up @@ -117,15 +36,6 @@ function location_search_replace(new_params) {
return '?' + search.toString();
}

function get_ext_icon(ext) {
for (let type in ext2Icon) {
if (ext2Icon[type].indexOf(ext.toLowerCase()) >= 0) {
return 'fa-file-' + type;
}
}
return "fa-file";
}

jQuery(document).ready(function() {
// Drop all support of IE 6-11
if ($.zui.browser.ie) {
Expand All @@ -147,7 +57,7 @@ jQuery(document).ready(function() {
});
}
});

// Captcha Img Re-flush
let captcha_img_another = $('.captcha_img');
captcha_img_another.on('click',function () {
Expand Down Expand Up @@ -231,6 +141,22 @@ jQuery(document).ready(function() {
});

// View Torrent File list
let ext2Icon = $.zui.store.get('rid_ext2Icon');
if (!ext2Icon) {
$.getJSON('/static/json/ext2Icon.json',function (data) {
ext2Icon = data;
$.zui.store.set('rid_ext2Icon', ext2Icon);
})
}
function get_ext_icon(ext) {
for (let type in ext2Icon) {
if (ext2Icon[type].indexOf(ext.toLowerCase()) >= 0) {
return 'fa-file-' + type;
}
}
return "fa-file";
}

$('.torrent-files').click(function () {
let that = $(this);
let tid = that.attr('data-tid');
Expand Down
14 changes: 14 additions & 0 deletions apps/public/static/json/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ext2Icon.json

The icon map for file extension

Notice: The map key should has the fontawesome icon like `fa-file-${v}`

Knowledge:
- file format of 'video','audio' are from MPC-HC : https://mpc-hc.org/
- file format of 'image' are from arthurvr/image-extensions : https://github.com/arthurvr/image-extensions
- file format of 'alt' are from sindresorhus/text-extensions: https://github.com/sindresorhus/text-extensions, And remove the duplicate element.
- file format of 'archive are form Wikipedia : https://en.wikipedia.org/wiki/List_of_archive_formats
- file format of 'word','powerpoint','excel' are from MicroSoft Office 365 ( Word, PowerPoint, Excel )

See more group information on : <https://github.com/Rhilip/RidPT/blob/e8c9962d26/apps/public/static/js/main.js#L7-L86>
101 changes: 101 additions & 0 deletions apps/public/static/json/ext2Icon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"video": [
"avi",
"mpg", "mpeg", "mpe", "m1v", "m2v", "mpv2", "mp2v", "pva", "evo", "m2p",
"ts", "tp", "trp", "m2t", "m2ts", "mts", "rec", "ssif",
"vob", "ifo",
"mkv", "mk3d",
"webm",
"mp4", "m4v", "mp4v", "mpv4", "hdmov",
"mov",
"3gp", "3gpp", "3ga",
"3g2", "3gp2",
"flv", "f4v",
"ogm", "ogv",
"rm", "rmvb", "rt", "ram", "rpm", "rmm", "rp", "smi", "smil",
"wmv", "wmp", "wm", "asf",
"smk", "bik",
"fli", "flc", "flic",
"dsm", "dsv", "dsa", "dss",
"divx", "amv",
"asx", "m3u", "m3u8", "pls", "wvx", "wax", "wmx", "mpcpl",
"mpls", "bdmv"
],
"audio": [
"ac3",
"dts", "dtshd", "dtsma",
"aif", "aifc", "aiff",
"alac",
"amr",
"ape", "apl",
"au", "snd",
"cda",
"flac",
"m4a", "m4b", "m4r", "aac",
"mid", "midi", "rmi",
"mka",
"mp3",
"mpa", "mp2", "m1a", "m2a",
"mpc",
"ofr", "ofs",
"ogg", "oga",
"opus",
"ra",
"tak",
"tta",
"wav",
"wma",
"wv",
"aob", "mlp", "thd"
],
"image": [
"ase","art","bmp","blp","cd5","cit","cpt","cr2","cut","dds","dib","djvu","egt","exif","gif","gpl","grf",
"icns","ico","iff","jng","jpeg","jpg","jfif","jp2","jps","lbm","max","miff","mng","msp","nitf","ota",
"pbm","pc1","pc2","pc3","pcf","pcx","pdn","pgm","PI1","PI2","PI3","pict","pct","pnm","pns","ppm","psb","psd","pdd","psp","px","pxm","pxr",
"qfx","raw","rle","sct","sgi","rgb","int","bw","tga","tiff","tif","vtf","xbm","xcf","xpm",
"3dv","amf","ai","awg","cgm","cdr","cmx","dxf","e2d","egt","eps","fs","gbr","odg","svg","stl","vrml","x3d",
"sxd","v2d","vnd","wmf","emf","art","xar","png","webp","jxr","hdp","wdp","cur","ecw","iff","lbm","liff","nrrd",
"pam","pcx","pgf","sgi","rgb","rgba","bw","int","inta","sid","ras","sun","tga"],
"alt": [
"ada","adb","ads","applescript","au3","as","asc","ascx","ascii","asm","asmx","asp","aspx","atom","awk",
"bas","bash","bashrc","bat","bbcolors","bcp","bdsgroup","bdsproj","bib","bowerrc",
"c","cbl","cc","cfc","cfg","cfm","cfml","cgi","clj","cljs","cls","cmake","cmd","cnf","cob","code-snippets","coffee","coffeekup","conf","cp","cpp","cpy","crt","cs","csh","cson","csproj","csr","css","csslintrc","ctl","curlrc","cxx",
"d","dart","dfm","diff","dof","dpk","dpr","dproj","dtd",
"eco","editorconfig","ejs","el","elm","emacs","eml","ent","erb","erl","eslintignore","eslintrc","ex","exs",
"f03","f77","f90","f95","fish","for","fpp","frm","fsproj","fsx","ftn",
"gemrc","gemspec","gitattributes","gitconfig","gitignore","gitkeep","gitmodules","go","gpp","gradle","groovy","groupproj","grunit","gtmpl","gvimrc",
"h","haml","hbs","hgignore","hh","hrl","hpp","hs","hta","htaccess","htc","htm","html","htpasswd","hxx",
"iced","iml","inc","ini","ino","irbrc","itcl","itermcolors","itk",
"jade","java","jhtm","jhtml","js","jscsrc","jshintignore","jshintrc","json","json5","jsonld","jsp","jspx","jsx",
"ksh",
"less","lhs","lisp","log","ls","lsp","lua",
"m","m4","mak","map","markdown","master","md","mdown","mdwn","mdx","metadata","mht","mhtml","mjs","mk","mkd","mkdn","mkdown","ml","mli","mm","mxml",
"nfm","nfo","noon","npmignore","npmrc","nuspec","nvmrc",
"ops",
"pas","pasm","patch","pbxproj","pch","pem","pg","php","php3","php4","php5","phpt","phtml","pir","pl","pm","pmc","pod","prettierrc","properties","props","pt","pug","purs","py","pyx",
"r","rake","rb","rbw","rc","rdoc","rdoc_options","resx","rexx","rhtml","rjs","rlib","ron","rs","rss","rst","rtf","rvmrc","rxml",
"s","sass","scala","scm","scss","seestyle","sh","shtml","sln","sls","spec","sql","sqlite","sqlproj","ss","sss","st","strings","sty","styl","stylus","sub","sublime-build","sublime-commands","sublime-completions","sublime-keymap","sublime-macro","sublime-menu","sublime-project","sublime-settings","sublime-workspace","sv","svc","swift",
"t","tcl","tcsh","terminal","tex","text","textile","tg","tk","tmLanguage","tmTheme","tmpl","tpl","tsv","tsx","tt","tt2","ttml","twig","txt",
"v","vb","vbproj","vbs","vcproj","vcxproj","vh","vhd","vhdl","vim","viminfo","vimrc","vm","vue",
"webapp",
"x-php","wsc","xaml","xht","xhtml","xml","xs","xsd","xsl","xslt",
"y","yaml","yml",
"zsh","zshrc"
],
"archive": [
"a", "ar", "cpio", "shar", "lbr", "iso", "mar", "sbx", "tar",
"bz2", "f", "gz", "lz", "lzma", "lzo", "rz", "sfark", "sz", "xz", "z",
"7z", "s7z", "ace", "afa", "alz", "apk", "arc", "arj", "b1", "b6z", "ba", "bh", "cab", "car", "cfs", "cpt", "dar", "dd", "dgc", "dmg",
"ear", "gca", "ha", "hki", "ice", "jar", "kgb", "lzh", "lha", "lzx", "pak", "partimg", "paq6", "paq7", "paq8", "pea", "pim",
"qda", "rar", "rk", "sda", "sea", "sen", "sfx", "shk", "sitx", "sqx", "tgz", "tbz2", "tlz", "xz", "txz", "uc", "uc0", "uc2", "ucn",
"ur2", "ue2", "uca", "war", "wim", "xar", "xp3", "yz1", "zip", "zipx", "zoo", "zpaq", "zz",
"ecc", "ecsbx", "par", "par2", "rev"
],
"word": ["doc", "docx", "docm", "dotx", "dotm", "dot", "odt"],
"powerpoint": ["ppt", "pptx", "pptm", "potx", "potm", "pot", "ppsx", "ppsm", "pps", "ppam", "ppa", "odp"],
"excel": ["xlsx", "xlsm", "xlsb", "xls", "xltx", "xltm", "xlt", "xlam", "xla", "ods"],
"pdf": ["pdf"],
"csv": ["csv"],
"code": [],
"contract": []
}
2 changes: 1 addition & 1 deletion framework/View/Conversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function register(Engine $engine)

public static function setDefault(&$array, $defaults)
{
if (is_string($array)) $array = [$array];
if (!is_array($array)) $array = [$array];
foreach ($defaults as $key => $default) {
if (!array_key_exists($key, $array)) {
$array[$key] = $default;
Expand Down

0 comments on commit bec2fc0

Please sign in to comment.