Unordered files when importing manga pic from zip files
coda1997 opened this issue · 4 comments
It's wired thing, when Manga imported into this web from zip files, the order of all pictures are mixed. I do not know the order is by file name or the creation date or else, but It's a bug making me so mad through. I can work around it by unzipping comic first, import the folder then. But it is better if the import from zip files work fine.
I will find the code in your repo if I have the ability to fix that.
Anyway, it is a awesome project that manga fans LOVE this so much.
I found the issue in this code
const zipFiles = Object.keys(zipContent.files).sort().map((filename) => zipContent.files[filename])
The default sort order is ascending, built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values.
Thus sorting this array const array1 = ['1','2','3','4','5','6','7','8','9','10','20','30','40'];
will obtain the unexpected results
Array ["1", "10", "2", "20", "3", "30", "4", "40", "5", "6", "7", "8", "9"]
To fix this bug, give a lambda function as a comparator like:
array1.sort(function(a, b){return a-b})
I tried to solve this issue, and found another problems due to macOS compression. When macOS compresses a couple of file, it append __MACOS directory which should be emitted.
I fork your repo and add filter method to eliminate this directory. And sort the array by it name without extension only.
This works for me, but I am not sure other fans could use that because the filename can only be number.
not good at english so i use chinese to answer.
我不能直接将排序的方法,换成你说的。因为不能确保压缩包里文件的名字,都是使用数字组成的字符串,这挺麻烦的。
对,可能有许多用户会使用不是数字组成的字符串作为文件名字。这个排序问题还是比较棘手的,python也有这种问题,默认用的字典序。我自己fork了一份用了一下数字的sort,挺好用的。就先这样work around了。多谢
想到一个办法,如果你是用macOS系统,那么可以先自己手动批量重命名文件,然后再打包成epub,这样导入文件的时候就不会因为字典排序,导致乱序问题。这个方法我经常用。