1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-09-28 22:40:50 +00:00

File: Add '.stl' and '.webp' as image extensions [#710]

This commit is contained in:
gnosygnu 2020-04-21 08:31:40 -04:00
parent 9c8650a4d9
commit b05e3cd188
7 changed files with 384 additions and 284 deletions

View File

@ -1,6 +1,6 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
Copyright (C) 2012-2020 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
@ -43,6 +43,8 @@ class Xobldr__fsdb_db__delete_small_files_ {
Ext_max_(rv, 1000, Xof_ext_.Id_ogv);
Ext_max_(rv, 400, Xof_ext_.Id_pdf);
Ext_max_(rv, 700, Xof_ext_.Id_djvu);
Ext_max_(rv, 500, Xof_ext_.Id_stl);
Ext_max_(rv, 500, Xof_ext_.Id_webp);
return rv;
}
private static void Ext_max_(int[] ary, int max, int... exts) {for (int ext : exts) ary[ext] = max;}

View File

@ -1,6 +1,6 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
Copyright (C) 2012-2020 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
@ -20,8 +20,10 @@ public class Xof_ext_ {
, Id_png = 1, Id_jpg = 2, Id_jpeg = 3, Id_gif = 4, Id_tif = 5, Id_tiff = 6
, Id_svg = 7, Id_djvu = 8, Id_pdf = 9
, Id_mid = 10, Id_ogg = 11, Id_oga = 12, Id_ogv = 13, Id_webm = 14
, Id_flac = 15, Id_bmp = 16, Id_xcf = 17, Id_wav = 18, Id_opus = 19;
public static final int Id__max = 20;
, Id_flac = 15, Id_bmp = 16, Id_xcf = 17, Id_wav = 18, Id_opus = 19
, Id_stl = 20, Id_webp = 21;
;
public static final int Id__max = 22;
public static final byte[]
Bry_png = Bry_.new_a7("png"), Bry_jpg = Bry_.new_a7("jpg"), Bry_jpeg = Bry_.new_a7("jpeg")
, Bry_gif = Bry_.new_a7("gif"), Bry_tif = Bry_.new_a7("tif"), Bry_tiff = Bry_.new_a7("tiff")
@ -29,6 +31,7 @@ public class Xof_ext_ {
, Bry_mid = Bry_.new_a7("mid"), Bry_ogg = Bry_.new_a7("ogg"), Bry_oga = Bry_.new_a7("oga")
, Bry_ogv = Bry_.new_a7("ogv"), Bry_webm = Bry_.new_a7("webm"), Bry_flac = Bry_.new_a7("flac")
, Bry_bmp = Bry_.new_a7("bmp"), Bry_xcf = Bry_.new_a7("xcf"), Bry_wav = Bry_.new_a7("wav"), Bry_opus = Bry_.new_a7("opus")
, Bry_stl = Bry_.new_a7("stl"), Bry_webp = Bry_.new_a7("webp")
;
public static final byte[][] Bry__ary = new byte[][]
{ Bry_.Empty, Bry_png, Bry_jpg, Bry_jpeg
@ -37,6 +40,7 @@ public class Xof_ext_ {
, Bry_mid, Bry_ogg, Bry_oga
, Bry_ogv, Bry_webm, Bry_flac
, Bry_bmp, Bry_xcf, Bry_wav, Bry_opus
, Bry_stl, Bry_webp
};
public static final byte[][] Mime_type__ary = new byte[][]
{ Bry_.new_a7("application/octet-stream"), Bry_.new_a7("image/png"), Bry_.new_a7("image/jpg"), Bry_.new_a7("image/jpeg")
@ -44,7 +48,10 @@ public class Xof_ext_ {
, Bry_.new_a7("image/svg+xml"), Bry_.new_a7("image/x.djvu"), Bry_.new_a7("application/pdf")
, Bry_.new_a7("application/x-midi"), Bry_.new_a7("video/ogg"), Bry_.new_a7("audio/oga")
, Bry_.new_a7("video/ogg"), Bry_.new_a7("video/webm"), Bry_.new_a7("audio/flac")
, Bry_.new_a7("image/bmp"), Bry_.new_a7("image/xcf"), Bry_.new_a7("audio/x-wav"), Bry_.new_a7("audio/opus")
, Bry_.new_a7("image/bmp")
, Bry_.new_a7("image/x-xcf") // changed from "/xcf"; DATE:2020-04-21
, Bry_.new_a7("audio/x-wav"), Bry_.new_a7("audio/opus")
, Bry_.new_a7("model/stl"), Bry_.new_a7("video/webp")
};
private static final Hash_adp id_hash = id_hash_new_();
private static Hash_adp id_hash_new_() {
@ -55,7 +62,7 @@ public class Xof_ext_ {
id_hash_new_(rv, Bry_mid, Id_mid); id_hash_new_(rv, Bry_ogg, Id_ogg); id_hash_new_(rv, Bry_oga, Id_oga);
id_hash_new_(rv, Bry_ogv, Id_ogv); id_hash_new_(rv, Bry_webm, Id_webm); id_hash_new_(rv, Bry_flac, Id_flac);
id_hash_new_(rv, Bry_bmp, Id_bmp); id_hash_new_(rv, Bry_xcf, Id_xcf); id_hash_new_(rv, Bry_wav, Id_wav);
id_hash_new_(rv, Bry_opus, Id_opus);
id_hash_new_(rv, Bry_opus, Id_opus); id_hash_new_(rv, Bry_stl, Id_stl); id_hash_new_(rv, Bry_webp, Id_webp);
return rv;
}
private static void id_hash_new_(Hash_adp hash, byte[] key, int val) {hash.Add(key, new Int_obj_val(val));}
@ -67,7 +74,7 @@ public class Xof_ext_ {
.Add_bry_bry(Bry_mid).Add_bry_bry(Bry_ogg).Add_bry_bry(Bry_oga)
.Add_bry_bry(Bry_ogv).Add_bry_bry(Bry_webm).Add_bry_bry(Bry_flac)
.Add_bry_bry(Bry_bmp).Add_bry_bry(Bry_xcf).Add_bry_bry(Bry_wav)
.Add_bry_bry(Bry_opus)
.Add_bry_bry(Bry_opus).Add_bry_bry(Bry_stl).Add_bry_bry(Bry_webp)
;
private static final Xof_ext[] Ary = new Xof_ext[Id__max];
@ -134,6 +141,7 @@ public class Xof_ext_ {
case Xof_ext_.Id_gif: case Xof_ext_.Id_tif: case Xof_ext_.Id_tiff:
case Xof_ext_.Id_svg:
case Xof_ext_.Id_bmp: case Xof_ext_.Id_xcf:
case Xof_ext_.Id_stl: case Xof_ext_.Id_webp:
return true;
default:
return false;
@ -144,6 +152,7 @@ public class Xof_ext_ {
case Xof_ext_.Id_png: case Xof_ext_.Id_jpg: case Xof_ext_.Id_jpeg:
case Xof_ext_.Id_gif: case Xof_ext_.Id_tif: case Xof_ext_.Id_tiff:
case Xof_ext_.Id_bmp: case Xof_ext_.Id_xcf:
case Xof_ext_.Id_stl: case Xof_ext_.Id_webp:
return true;
default:
return false;
@ -155,6 +164,7 @@ public class Xof_ext_ {
case Xof_ext_.Id_gif: case Xof_ext_.Id_tif: case Xof_ext_.Id_tiff:
case Xof_ext_.Id_svg: case Xof_ext_.Id_djvu: case Xof_ext_.Id_pdf:
case Xof_ext_.Id_bmp: case Xof_ext_.Id_xcf:
case Xof_ext_.Id_stl: case Xof_ext_.Id_webp:
return true;
default:
return false;
@ -196,10 +206,23 @@ public class Xof_ext_ {
}
public static int Id_view(int id) {
switch (id) {
case Xof_ext_.Id_svg: case Xof_ext_.Id_bmp: case Xof_ext_.Id_xcf: return Xof_ext_.Id_png;
case Xof_ext_.Id_tif: case Xof_ext_.Id_tiff: case Xof_ext_.Id_djvu: case Xof_ext_.Id_pdf:
case Xof_ext_.Id_ogg: case Xof_ext_.Id_ogv: case Xof_ext_.Id_webm: return Xof_ext_.Id_jpg;
default: return id;
// example image is rendered as .png; see wiki articles
case Xof_ext_.Id_svg:
case Xof_ext_.Id_bmp:
case Xof_ext_.Id_xcf:
case Xof_ext_.Id_stl: // https://en.wikipedia.org/wiki/STL_(file_format)
case Xof_ext_.Id_webp:// https://en.wikipedia.org/wiki/WebP
return Xof_ext_.Id_png;
case Xof_ext_.Id_tif:
case Xof_ext_.Id_tiff:
case Xof_ext_.Id_djvu:
case Xof_ext_.Id_pdf:
case Xof_ext_.Id_ogg:
case Xof_ext_.Id_ogv:
case Xof_ext_.Id_webm:
return Xof_ext_.Id_jpg;
default:
return id;
}
}
}

View File

@ -1,6 +1,6 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
Copyright (C) 2012-2020 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
@ -48,6 +48,8 @@ public class Xof_mime_minor_ {
mime_hash_itm_(rv, Mime_xcf , Xof_ext_.Id_xcf);
mime_hash_itm_(rv, Xof_ext_.Bry_wav , Xof_ext_.Id_wav);
mime_hash_itm_(rv, Xof_ext_.Bry_opus , Xof_ext_.Id_opus);
mime_hash_itm_(rv, Xof_ext_.Bry_stl , Xof_ext_.Id_stl);
mime_hash_itm_(rv, Xof_ext_.Bry_webp , Xof_ext_.Id_webp);
return rv;
}
private static void mime_hash_itm_(Hash_adp hash, byte[] key, int val) {hash.Add(key, new Int_obj_val(val));}

View File

@ -1,6 +1,6 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
Copyright (C) 2012-2020 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
@ -173,23 +173,21 @@ public class Xof_url_bldr {
tmp_bfr.Add(Bry_thumnbail_w_dot);
tmp_bfr.Add(ext.Ext());
}
else
tmp_bfr.Add(encoder_src_http.Encode(ttl)); // add ttl again; EX: "A.png"
switch (file_ext_id) {
case Xof_ext_.Id_svg:
case Xof_ext_.Id_bmp:
case Xof_ext_.Id_xcf:
tmp_bfr.Add_byte(Byte_ascii.Dot).Add(Xof_ext_.Bry_png); // add .png; EX: "A.svg" -> "A.svg.png" NOTE: MediaWiki always adds as lowercase
break;
case Xof_ext_.Id_pdf:
case Xof_ext_.Id_tif: // add .jpg EX: "A.tif" -> "A.tif.jpg" NOTE: MediaWiki always adds as lowercase
case Xof_ext_.Id_tiff:
case Xof_ext_.Id_ogg:
case Xof_ext_.Id_ogv:
case Xof_ext_.Id_djvu:
case Xof_ext_.Id_webm:
tmp_bfr.Add_byte(Byte_ascii.Dot).Add(Xof_ext_.Bry_jpg);
break;
else {
tmp_bfr.Add(encoder_src_http.Encode(ttl)); // add ttl again; EX: "A.png"
}
// add ".png" / ".jpg" suffix if file is image; NOTE: don't add if already .png or .jpg
if ( file_ext_id != Xof_ext_.Id_png
&& file_ext_id != Xof_ext_.Id_jpg) {
int file_view_id = Xof_ext_.Id_view(file_ext_id);
switch (file_view_id) {
case Xof_ext_.Id_png:
tmp_bfr.Add_byte(Byte_ascii.Dot).Add(Xof_ext_.Bry_png); // add .png; EX: "A.svg" -> "A.svg.png" NOTE: MediaWiki always adds as lowercase
break;
case Xof_ext_.Id_jpg: // add .jpg EX: "A.tif" -> "A.tif.jpg" NOTE: MediaWiki always adds as lowercase
tmp_bfr.Add_byte(Byte_ascii.Dot).Add(Xof_ext_.Bry_jpg);
break;
}
}
return this;
}
@ -225,5 +223,4 @@ public class Xof_url_bldr {
rv.time_dlm = Byte_ascii.Dash;
return rv;
}
public static final int Md5_dir_depth_2 = 2;
}

View File

@ -1,6 +1,6 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
Copyright (C) 2012-2020 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
@ -25,6 +25,8 @@ public class Xof_url_bldr__tst {
@Test public void Bmp() {fxt.Root_("http://test/").Md5_("70").Ttl_("A.bmp").W_(220).Expd_src_("http://test/thumb/7/70/A.bmp/220px-A.bmp.png").Test();}
@Test public void Pdf() {fxt.Root_("http://test/").Md5_("ef").Ttl_("A.pdf").W_(220).Expd_src_("http://test/thumb/e/ef/A.pdf/page1-220px-A.pdf.jpg").Test();}
@Test public void Pdf__page_2() {fxt.Root_("http://test/").Md5_("ef").Ttl_("A.pdf").W_(220).Expd_src_("http://test/thumb/e/ef/A.pdf/page2-220px-A.pdf.jpg").Page_(2).Test();}
@Test public void Stl() {fxt.Root_("http://test/").Md5_("62").Ttl_("A.stl").W_(220).Expd_src_("http://test/thumb/6/62/A.stl/220px-A.stl.png").Test();}
@Test public void Webp() {fxt.Root_("http://test/").Md5_("d9").Ttl_("A.webp").W_(220).Expd_src_("http://test/thumb/d/d9/A.webp/220px-A.webp.png").Test();}
@Test public void Long() {
String filename = String_.Repeat("A", 200) + ".png";
fxt.Root_("http://test/").Md5_("14").Ttl_(filename).W_(220)

View File

@ -0,0 +1,37 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.files.fsdb.tsts;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class Xof_file_ext__stl_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Make_orig() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.stl", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.stl", 440, 400));
fxt.Exec_get(Xof_exec_arg.new_orig("A.stl").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/6/2/A.stl/440px.png", "440,400");
}
@Test public void Make_thumb() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.stl", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.stl", 440, 400));
fxt.Exec_get(Xof_exec_arg.new_thumb("A.stl").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/6/2/A.stl/220px.png", "220,200");
}
}

View File

@ -0,0 +1,37 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.files.fsdb.tsts;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class Xof_file_ext__webp_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Make_orig() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.webp", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.webp", 440, 400));
fxt.Exec_get(Xof_exec_arg.new_orig("A.webp").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/d/9/A.webp/440px.png", "440,400");
}
@Test public void Make_thumb() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.webp", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.webp", 440, 400));
fxt.Exec_get(Xof_exec_arg.new_thumb("A.webp").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/d/9/A.webp/220px.png", "220,200");
}
}