1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-12-08 17:58:05 +00:00

Add a Zotero demo for the new http mechanism

An initial experiment for handling paginated APIs. This isn't perfect; it isn't possible to interrupt things, for example.
This commit is contained in:
jeremy@jermolene.com
2023-01-05 17:12:13 +00:00
parent 27f9df3af5
commit 4b9a6b5757
5 changed files with 151 additions and 3 deletions

View File

@@ -0,0 +1,39 @@
/*\
title: $:/core/modules/filters/url-ops.js
type: application/javascript
module-type: filteroperator
Filter operators for URL operations
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports["setquerystring"] = function(source,operator,options) {
var URL = $tw.browser ? window.URL : require("url").URL,
URLSearchParams = $tw.browser ? window.URLSearchParams : require("url").URLSearchParams,
name = operator.operands.length >= 1 ? operator.operands[0] : null,
value = operator.operands.length >= 2 ? operator.operands[1] : "",
results = [];
source(function(tiddler,title) {
var url;
try {
url = new URL(title);
} catch(e) {
}
if(url) {
var params = new URLSearchParams(url.search);
if(name) {
params.set(name,value);
}
url.search = params.toString();
results.push(url.toString());
}
});
return results;
};
})();

View File

@@ -66,9 +66,9 @@ HttpClient.prototype.handleHttpRequest = function(event) {
callback: function(err,data,xhr) {
var headers = {};
$tw.utils.each(xhr.getAllResponseHeaders().split("\r\n"),function(line) {
var parts = line.split(":");
if(parts.length === 2) {
headers[parts[0].toLowerCase()] = parts[1].trim();
var pos = line.indexOf(":");
if(pos !== -1) {
headers[line.substr(0,pos)] = line.substr(pos + 1).trim();
}
});
setBinding(bindStatus,xhr.status === 200 ? "complete" : "error");