Last active
May 24, 2024 14:16
-
-
Save scripting/1fc3f656748dbaa3d84aefc1322aa72c to your computer and use it in GitHub Desktop.
Revisions
-
scripting renamed this gist
May 24, 2024 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
scripting renamed this gist
May 24, 2024 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
scripting created this gist
May 24, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ See this issue report for background. https://github.com/scripting/wpIdentity/issues/1 Dave This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ { "name": "wpupload", "description": "Develop and test code to upload images to wordpress.com.", "version": "0.4.0", "main": "wpupload.js", "dependencies" : { "daveutils": "*", "wpcom": "*" } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ var myProductName = "wpupload", myVersion = "0.4.0"; const fs = require ("fs"); const utils = require ("daveutils"); const wpcom = require ("wpcom"); var config = { fname: "test.png" }; function readConfig (f, config, callback) { fs.readFile (f, function (err, jsontext) { if (!err) { try { jsontext = jsontext.toString (); var jstruct = JSON.parse (jsontext); for (var x in jstruct) { config [x] = jstruct [x]; } } catch (err) { console.log ("Error reading " + f); } } callback (); }); } function uploadMedia (accessToken, idSite, fname, theMedia, callback) { //5/24/24 by DW const wp = wpcom (accessToken); const site = wp.site (idSite); const media = site.media (); const options = { media: theMedia, filename: fname, media_type: "image/png" } media.uploadFile (options, function (err, jstruct) { if (err) { callback (err); } else { callback (undefined, jstruct); } }); } readConfig ("config.json", config, function (err, data) { if (err) { console.log (err.message); } else { console.log ("config == " + utils.jsonStringify (config)); fs.readFile (config.fname, function (err, media) { if (err) { console.log (err.message); } else { uploadMedia (config.accessToken, config.idSite, config.fname, media, function (err, data) { if (err) { console.log (err.message); } else { console.log (data); } }); } }); } });