kanasimi / wikiapi

JavaScript MediaWiki API for node.js
https://kanasimi.github.io/wikiapi/
BSD 3-Clause "New" or "Revised" License
47 stars 5 forks source link

.upload(): The \"token\" parameter must be set ? #70

Closed hugolpz closed 6 months ago

hugolpz commented 6 months ago

Hello @kanasimi ,

Not asking you to dive in, but are you familiar from past experience with such trouble when using .upload() ? Second case is similar to unsolved #69 I had 2 weeks back.

options.text

When I code :

wiki.upload({
    file_path: filepathWav,
    filename: uploadFilename,  // default : keep filename
    comment: `Upload Shtooka recorder file ${title} as Lingua Libre item.`,
    text: uploadTemplate,
    ignorewarnings: 1,  // overwrite
    permission: `{{own}}`,
    license: ['{{cc-by-sa-3.0}}' ],
    bot: 1,
    //  ...options,
    //  description: `Chinese mandarin ''« ${title} »''`,
    //  author: `[[User:${USER.split('@')[0]}|]]`,
});

Then console is :

get_API_parameters: 快取 commonswiki 的 API 模組資訊:模組路徑為 upload 
/home/yug/Documents/communal/WikiVoc/Dragons_Bot/node_modules/cejs/application/net/wiki/edit.js:1426
                                error = new Error(JSON.stringify(error));
                                        ^

Error: {"code":"missingparam","info":"The \"token\" parameter must be set.","*":"See https://commons.wikimedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/> for notice of API deprecations and breaking changes."}
    at upload_callback (/home/yug/Documents/communal/WikiVoc/Dragons_Bot/node_modules/cejs/application/net/wiki/edit.js:1426:13)
    at check_session_badtoken (/home/yug/Documents/communal/WikiVoc/Dragons_Bot/node_modules/cejs/application/net/wiki/query.js:208:4)
    at XMLHttp_handler (/home/yug/Documents/communal/WikiVoc/Dragons_Bot/node_modules/cejs/application/net/wiki/query.js:739:4)
    at IncomingMessage.<anonymous> (/home/yug/Documents/communal/WikiVoc/Dragons_Bot/node_modules/cejs/application/net/Ajax.js:2318:6)
    at IncomingMessage.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v18.13.0

options

When I code :

let options = {
    author: `[[User:${USER.split('@')[0]}|]]`,
    date: new Date().toISOString().split('T')[0],
    //source_url: 'https://github.com/kanasimi/wikiapi',
    permission: '{{own}}',
    other_versions: '',
    other_fields: '',
    license: ['{{self|cc-by-sa-4.0}}' ],
    categories: [`[[Category:WikiVoc]]`, `[[Category:${USER.split('@')[0]} test: upload]]` ],
    bot: 1,
   // tags:"tag1|tag2",
};
wiki.upload({
    file_path: filepathWav,
    filename: uploadFilename,  // default : keep filename
    comment: `Upload Shtooka recorder file ${title} as Lingua Libre item.`,
    //text: uploadTemplate,
    ignorewarnings: 1,  // overwrite
      ...options,
      description: `Chinese mandarin ''« ${title} »''`,
});

Then console is :

get_API_parameters: 快取 commonswiki 的 API 模組資訊:模組路徑為 upload 
/home/yug/Documents/communal/WikiVoc/Dragons_Bot/node_modules/cejs/application/net/wiki/task.js:2162
                        } else if (this.last_page.id && ('missing' in this.last_page)
                                                  ^

TypeError: Cannot read properties of undefined (reading 'id')
    at wiki_API.next (/home/yug/Documents/communal/WikiVoc/Dragons_Bot/node_modules/cejs/application/net/wiki/task.js:2162:30)
    at check_structured_data (/home/yug/Documents/communal/WikiVoc/Dragons_Bot/node_modules/cejs/application/net/wiki/edit.js:1348:12)
    at upload_callback (/home/yug/Documents/communal/WikiVoc/Dragons_Bot/node_modules/cejs/application/net/wiki/edit.js:1429:38)
    at check_session_badtoken (/home/yug/Documents/communal/WikiVoc/Dragons_Bot/node_modules/cejs/application/net/wiki/query.js:208:4)
    at XMLHttp_handler (/home/yug/Documents/communal/WikiVoc/Dragons_Bot/node_modules/cejs/application/net/wiki/query.js:739:4)
    at IncomingMessage.<anonymous> (/home/yug/Documents/communal/WikiVoc/Dragons_Bot/node_modules/cejs/application/net/Ajax.js:2318:6)
    at IncomingMessage.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v18.13.0
kanasimi commented 6 months ago

I noticed that it seems that you are not using the latest version? I've made some changes since then, so you can try running it with the latest version. Also, if #69 is not resolved, you can post the latest results in that issue.

hugolpz commented 6 months ago

[EDIT] Investigation moved to #69 .

kanasimi commented 6 months ago

Ok