mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-09-22 12:01:15 -04:00
Merge pull request #140 from peter-x/pathfix
Fix for finding some files in ZIM.
This commit is contained in:
commit
704f1dae75
@ -19,8 +19,8 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with Evopedia (file LICENSE-GPLv3.txt). If not, see <http://www.gnu.org/licenses/>
|
* along with Evopedia (file LICENSE-GPLv3.txt). If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geometry'],
|
define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geometry', 'utf8'],
|
||||||
function($, evopediaTitle, evopediaArchive, zimArchive, zimDirEntry, util, geometry) {
|
function($, evopediaTitle, evopediaArchive, zimArchive, zimDirEntry, util, geometry, utf8) {
|
||||||
|
|
||||||
var localEvopediaArchive;
|
var localEvopediaArchive;
|
||||||
var localZimArchive;
|
var localZimArchive;
|
||||||
@ -172,7 +172,7 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom
|
|||||||
equal(title._name, "Diego_Velázquez", "Name of the title is correct");
|
equal(title._name, "Diego_Velázquez", "Name of the title is correct");
|
||||||
start();
|
start();
|
||||||
};
|
};
|
||||||
localEvopediaArchive.getTitleByName("Diego_Velázquez").then(callbackFunction);
|
localEvopediaArchive.getTitleByName("A/Diego_Velázquez").then(callbackFunction);
|
||||||
});
|
});
|
||||||
asyncTest("check getTitleByName with quote : Hundred Years' War", function() {
|
asyncTest("check getTitleByName with quote : Hundred Years' War", function() {
|
||||||
expect(2);
|
expect(2);
|
||||||
@ -181,7 +181,7 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom
|
|||||||
equal(title._name, "Hundred_Years'_War", "Name of the title is correct");
|
equal(title._name, "Hundred_Years'_War", "Name of the title is correct");
|
||||||
start();
|
start();
|
||||||
};
|
};
|
||||||
localEvopediaArchive.getTitleByName("Hundred_Years'_War").then(callbackFunction);
|
localEvopediaArchive.getTitleByName("A/Hundred_Years'_War").then(callbackFunction);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("check parseTitleFromId", function() {
|
test("check parseTitleFromId", function() {
|
||||||
@ -219,7 +219,7 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom
|
|||||||
equal(title._name, "AIDS", "Name of the title is correct");
|
equal(title._name, "AIDS", "Name of the title is correct");
|
||||||
localEvopediaArchive.readArticle(title, callbackArticleRead);
|
localEvopediaArchive.readArticle(title, callbackArticleRead);
|
||||||
};
|
};
|
||||||
localEvopediaArchive.getTitleByName("AIDS").then(callbackTitleFound);
|
localEvopediaArchive.getTitleByName("A/AIDS").then(callbackTitleFound);
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest("check getTitleByName with a title name that does not exist in the archive", function() {
|
asyncTest("check getTitleByName with a title name that does not exist in the archive", function() {
|
||||||
@ -228,7 +228,7 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom
|
|||||||
ok(title === null, "No title found because it does not exist in the archive");
|
ok(title === null, "No title found because it does not exist in the archive");
|
||||||
start();
|
start();
|
||||||
};
|
};
|
||||||
localEvopediaArchive.getTitleByName("abcdef").then(callbackTitleFound);
|
localEvopediaArchive.getTitleByName("A/abcdef").then(callbackTitleFound);
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest("check loading a math image", function() {
|
asyncTest("check loading a math image", function() {
|
||||||
@ -505,7 +505,7 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom
|
|||||||
});
|
});
|
||||||
asyncTest("article '(The Night Time Is) The Right Time' correctly redirects to 'Night Time Is the Right Time'", function() {
|
asyncTest("article '(The Night Time Is) The Right Time' correctly redirects to 'Night Time Is the Right Time'", function() {
|
||||||
expect(6);
|
expect(6);
|
||||||
localZimArchive.getTitleByName("(The_Night_Time_Is)_The_Right_Time.html").then(function(title) {
|
localZimArchive.getTitleByName("A/(The_Night_Time_Is)_The_Right_Time.html").then(function(title) {
|
||||||
ok(title !== null, "Title found");
|
ok(title !== null, "Title found");
|
||||||
ok(title.isRedirect(), "Title is a redirect.");
|
ok(title.isRedirect(), "Title is a redirect.");
|
||||||
equal(title.name(), "(The Night Time Is) The Right Time", "Correct redirect title name.");
|
equal(title.name(), "(The Night Time Is) The Right Time", "Correct redirect title name.");
|
||||||
@ -519,10 +519,9 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom
|
|||||||
});
|
});
|
||||||
asyncTest("Image 'm/RayCharles_AManAndHisSoul.jpg' can be loaded", function() {
|
asyncTest("Image 'm/RayCharles_AManAndHisSoul.jpg' can be loaded", function() {
|
||||||
expect(4);
|
expect(4);
|
||||||
localZimArchive.getTitleByName("m/RayCharles_AManAndHisSoul.jpg").then(function(title) {
|
localZimArchive.getTitleByName("I/m/RayCharles_AManAndHisSoul.jpg").then(function(title) {
|
||||||
console.log(title);
|
|
||||||
ok(title !== null, "Title found");
|
ok(title !== null, "Title found");
|
||||||
equal(title.url, "m/RayCharles_AManAndHisSoul.jpg", "URL is correct.");
|
equal(title.url, "I/m/RayCharles_AManAndHisSoul.jpg", "URL is correct.");
|
||||||
localZimArchive.readBinaryFile(title, function(title, data) {
|
localZimArchive.readBinaryFile(title, function(title, data) {
|
||||||
equal(data.length, 4951, "Data length is correct.");
|
equal(data.length, 4951, "Data length is correct.");
|
||||||
var beginning = new Uint8Array([255, 216, 255, 224, 0, 16, 74, 70,
|
var beginning = new Uint8Array([255, 216, 255, 224, 0, 16, 74, 70,
|
||||||
|
@ -769,9 +769,10 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
|
|||||||
var titleName = event.data.titleName;
|
var titleName = event.data.titleName;
|
||||||
var messagePort = event.ports[0];
|
var messagePort = event.ports[0];
|
||||||
var readFile = function(title) {
|
var readFile = function(title) {
|
||||||
console.log("Found title.");
|
if (title === null) {
|
||||||
if (title.isRedirect()) {
|
console.error("Title " + titleName + " not found in archive.");
|
||||||
console.log("Following redirect...");
|
messagePort.postMessage({'action': 'giveContent', 'titleName' : titleName, 'content': ''});
|
||||||
|
} else if (title.isRedirect()) {
|
||||||
selectedArchive.resolveRedirect(title, readFile);
|
selectedArchive.resolveRedirect(title, readFile);
|
||||||
} else {
|
} else {
|
||||||
console.log("Reading binary file...");
|
console.log("Reading binary file...");
|
||||||
@ -781,9 +782,7 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("Fetching title " + titleName);
|
|
||||||
selectedArchive.getTitleByName(titleName).then(readFile).fail(function() {
|
selectedArchive.getTitleByName(titleName).then(readFile).fail(function() {
|
||||||
console.log("could not find title:" + arguments);
|
|
||||||
messagePort.postMessage({'action': 'giveContent', 'titleName' : titleName, 'content': new UInt8Array()});
|
messagePort.postMessage({'action': 'giveContent', 'titleName' : titleName, 'content': new UInt8Array()});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -121,6 +121,10 @@ define(['zimfile', 'zimDirEntry', 'util', 'utf8'],
|
|||||||
return that._file.dirEntryByTitleIndex(i).then(function(dirEntry) {
|
return that._file.dirEntryByTitleIndex(i).then(function(dirEntry) {
|
||||||
if (dirEntry.title == "")
|
if (dirEntry.title == "")
|
||||||
return -1; // ZIM sorts empty titles (assets) to the end
|
return -1; // ZIM sorts empty titles (assets) to the end
|
||||||
|
else if (dirEntry.namespace < "A")
|
||||||
|
return 1;
|
||||||
|
else if (dirEntry.namespace > "A")
|
||||||
|
return -1;
|
||||||
return prefix < dirEntry.title ? -1 : 1;
|
return prefix < dirEntry.title ? -1 : 1;
|
||||||
});
|
});
|
||||||
}, true).then(function(firstIndex) {
|
}, true).then(function(firstIndex) {
|
||||||
@ -206,17 +210,22 @@ define(['zimfile', 'zimDirEntry', 'util', 'utf8'],
|
|||||||
var that = this;
|
var that = this;
|
||||||
return util.binarySearch(0, this._file.articleCount, function(i) {
|
return util.binarySearch(0, this._file.articleCount, function(i) {
|
||||||
return that._file.dirEntryByUrlIndex(i).then(function(dirEntry) {
|
return that._file.dirEntryByUrlIndex(i).then(function(dirEntry) {
|
||||||
if (titleName < dirEntry.url)
|
var url = dirEntry.namespace + "/" + dirEntry.url;
|
||||||
|
if (titleName < url)
|
||||||
return -1;
|
return -1;
|
||||||
else if (titleName > dirEntry.url)
|
else if (titleName > url)
|
||||||
return 1;
|
return 1;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}).then(function(index) {
|
}).then(function(index) {
|
||||||
|
if (index === null) return null;
|
||||||
return that._file.dirEntryByUrlIndex(index);
|
return that._file.dirEntryByUrlIndex(index);
|
||||||
}).then(function(dirEntry) {
|
}).then(function(dirEntry) {
|
||||||
return that._dirEntryToTitleObject(dirEntry);
|
if (dirEntry === null)
|
||||||
|
return null;
|
||||||
|
else
|
||||||
|
return that._dirEntryToTitleObject(dirEntry);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ define([], function() {
|
|||||||
this.redirectTarget = dirEntryData.redirectTarget;
|
this.redirectTarget = dirEntryData.redirectTarget;
|
||||||
this.cluster = dirEntryData.cluster;
|
this.cluster = dirEntryData.cluster;
|
||||||
this.blob = dirEntryData.blob;
|
this.blob = dirEntryData.blob;
|
||||||
this.url = dirEntryData.url;
|
this.url = dirEntryData.namespace + '/' + dirEntryData.url;
|
||||||
this.title = dirEntryData.title;
|
this.title = dirEntryData.title;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user