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_file is not a function #22

Closed hugolpz closed 3 years ago

hugolpz commented 3 years ago
const Wikiapi= require('wikiapi');
const fetch  = require('node-fetch');
const fs     = require('fs');
const logins = require('./logins-ShufaBot.js');
const files  = require('./data/zi-reds.js');     // to get the list: ls -1 *.svg > zi-reds.js

// PURPOSE: Script uploads file 丁-red.png and similar to Commons.

// Edit login credentials
var USER = logins.commons.user,
    PASS = logins.commons.pass,
    API  = logins.commons.api;
    wikicode = '';
    console.log('Username:', USER);

(async () => {
    // Connect
    console.log('Connects');
    const targetWiki = new Wikiapi;
    await targetWiki.login(USER, PASS, API);
    console.log('Connected!');
    // upload file / media
    for(i=0;i<files.length;i++){
        let zi = files[i].zi;
        wikicode=`{{SOlicense|${zi}||red.png||license=PD}}`;
        let result = await targetWiki.upload_file({ 
                file_path: `./reds/png/${zi}.png`,
                comment: `Upload red stroke order for Chinese character ${zi}.`, 
                text: wikicode 
        });
    }
})();

Then:

$ node ./create-Commons-upload.js --trace-warnings
Username: ShufaBot@ShufaBot             # personal console.log
Connects
get_API_parameters: Set enwiki: path=query+siteinfo
get_API_parameters: Set commonswiki: path=query+siteinfo
Connected!                                              # personal console.log
(node:48717) UnhandledPromiseRejectionWarning: TypeError: targetWiki.upload_file is not a function
    at /home/yug/Documents/DragonsBot/create-Commons-upload.js:25:36
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:48717) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:48717) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
hugolpz commented 3 years ago

.upload_file doesn't exist anymore due to recent edits. Doc should be changed.

hugolpz commented 3 years ago

PR: #23 (update comments within wikiapi.js), #24 (readme.md).

May worth editing a bit our previous chats on the matter (here), so later readers and users are not confused.

EDIT: I corrected mine 👍🏼

kanasimi commented 3 years ago

fixed