fix: import not working if auth enabled

This commit is contained in:
Nazar Kanaev 2021-02-12 10:46:14 +00:00
parent 6a828532cb
commit ce1914419a

View File

@ -1,11 +1,17 @@
"use strict"; "use strict";
(function() { (function() {
var xfetch = function(resource, init) {
init = init || {}
if (['post', 'put', 'delete'].indexOf(init.method) !== -1) {
init['headers'] = init['headers'] || {}
init['headers']['x-requested-by'] = 'yarr'
}
return fetch(resource, init)
}
var api = function(method, endpoint, data) { var api = function(method, endpoint, data) {
var headers = {'Content-Type': 'application/json'} var headers = {'Content-Type': 'application/json'}
if (['post', 'put', 'delete'].indexOf(method) !== -1) return xfetch(endpoint, {
headers['x-requested-by'] = 'yarr'
return fetch(endpoint, {
method: method, method: method,
headers: headers, headers: headers,
body: JSON.stringify(data), body: JSON.stringify(data),
@ -87,7 +93,7 @@
return api('get', './api/status').then(json) return api('get', './api/status').then(json)
}, },
upload_opml: function(form) { upload_opml: function(form) {
return fetch('./opml/import', { return xfetch('./opml/import', {
method: 'post', method: 'post',
body: new FormData(form), body: new FormData(form),
}) })
@ -96,7 +102,7 @@
return api('post', './logout') return api('post', './logout')
}, },
crawl: function(url) { crawl: function(url) {
return fetch('./page?url=' + url).then(function(res) { return xfetch('./page?url=' + url).then(function(res) {
return res.text() return res.text()
}) })
} }