You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please be aware, that the code examples below are very condensed and intentionally omit the recommended try..catch construct as well as the async framing.
This is a syntactic sugar function to the generic info provider function listItems().
Example: Log out all files of blog alias 'mmm'
const td = new Twoday.Twoday('prod');
await td.login();
const alias = 'mmm';
const resInfos = await td.listFiles(alias);
console.log(`Blog "${alias}" features the following files:`);
resInfos.forEach(file => console.log(file.name));
Check if a specific file does exist on a blog alias
tFileID is the resulting name tag for the file, either defined by tFileInfo.name or derived by the system. If the same file name already exists, a new entry will be created and a sequential number will be added to tFileID (starting with "0"). It is strongly recommended to always check/use the returned tFileID as this may differ from the originally intended file name.
If the file does already exist, a copy will be created.
Example: Create a JSON file with the name "version" on blog alias neonwilderness
const path = require('path');
...
const td = new Twoday.Twoday('prod');
await td.login();
const fileID = await td.createFile('neonwilderness', {
name: 'version',
path: path.resolve(process.cwd(), './version.json'),
description: 'A JSON file that keeps the current script versions used on the blog.'
});
console.log(`The name tag for this file is: ${fileID}.`);
Example: Create a test JavaScript file and immediately delete it again
const path = require('path');
...
const td = new Twoday.Twoday('prod');
await td.login();
const alias = 'neonwilderness';
const file = {
name: 'test123',
path: path.resolve(process.cwd(), './test123.js'),
description: 'A test file that will quickly be deleted.'
};
const fileID = await td.createFile(alias, file);
await td.deleteFile(alias, fileID);
You should not use file.name as a param to td.deleteFile, as the name tag may have been altered by the system (i.e. in case 'test123' already existed).