diff --git a/src/content/mytinytodo.js b/src/content/mytinytodo.js index 8076b0e..3fe78f4 100644 --- a/src/content/mytinytodo.js +++ b/src/content/mytinytodo.js @@ -1,6 +1,6 @@ /* This file is a part of myTinyTodo. - (C) Copyright 2009-2010,2020-2023 Max Pozdeev + (C) Copyright 2009-2010,2020-2025 Max Pozdeev Licensed under the GNU GPL version 2 or any later. See file COPYRIGHT for details. */ @@ -2744,17 +2744,7 @@ function newTaskCounter() }); }); - fetch(_mtt.apiUrl + 'tasks/newCounter', { - method: 'POST', - credentials: 'same-origin', // old browsers - headers: { - 'Content-Type': 'application/json', - 'MTT-Token': _mtt.options.token, - }, - body: JSON.stringify(params) - }) - .then(response => response.json()) - .then(json => { + _mtt.db.request("newTaskCounter", params, json => { if (json && json.ok) { let counters = {}; let curCounter = 0; diff --git a/src/content/mytinytodo_api.js b/src/content/mytinytodo_api.js index f981911..03ae87c 100644 --- a/src/content/mytinytodo_api.js +++ b/src/content/mytinytodo_api.js @@ -1,6 +1,6 @@ /* This file is a part of myTinyTodo. - (C) Copyright 2010,2020-2023 Max Pozdeev + (C) Copyright 2010,2020-2025 Max Pozdeev Licensed under the GNU GPL version 2 or any later. See file COPYRIGHT for details. */ @@ -227,6 +227,29 @@ MytinytodoAjaxApi.prototype = { }); }, + newTaskCounter(params, callback) { + fetch(mytinytodo.apiUrl + 'tasks/newCounter', { + method: 'POST', + credentials: 'same-origin', // old browsers + headers: { + 'Content-Type': 'application/json', + 'MTT-Token': mytinytodo.options.token, + }, + body: JSON.stringify(params) + }) + .then((response) => { + if (!response.ok) throw response; + return response.json(); + }) + .catch((e) => { + if (e instanceof Error) console.log("newTaskCounter fetch error: ", e); + else console.log("newTaskCounter fetch error, HTTP status code: " + e.status); + }) + .then(json => { + callback(json) + }); + }, + // Lists loadLists(params, callback) {