1.0.6 • Published 4 years ago

sharexenjs v1.0.6

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

ShareXenJS - Global

Zallom's Twitter Team Wyvern's Twitter Team Wyvern's Discord ShareXenJS's NPM

ShareXenJS is a powerful javascript package for ShareXen, a ShareX Custom Uploader.

Features

Please note that this package make easier the integration of ShareXen into a nodejs application (in a Discord bot for example). Features may be changed during updates.

Installation

npm i sharexenjs

ShareXenJS - Usage

Before using this module please have first a functional ShareXen Server plus a functional token.

Requiring the module and giving the necessary information:

// Requiring the module
const sharexen = require("sharexenjs");

// Give him the necessary information
sharexen.login(WAY, TOKEN);
  • The WAY is a link to the ShareXen Server PHP file on your webserver.
  • The TOKEN is the character sequence that allows you to authenticate yourself on the ShareXen Server.

Upload a File

The function "upload" returns either an error or the response from the ShareXen Server.

In case of classic response, the response will contain:

NameTypeDescription
errbooleanPresence of error ?
api_versionStringCurrent API version number (SemVer).
endpointStringCalled API endpoint, in this case: "upload".
codeIntegerMirror of the returned HTTP code.
filenameStringName of the file as stored on the server.
urlStringURL for the new file.
deletion_urlStringFull deletion URL for the new file.
keyStringSecurity key for the new file.
iterationsIntegerAttempts at generating a unique filename.
timeFloatScript execution time, in seconds.

In case of error, the response will contain:

NameTypeDescription
errbooleanPresence of error ?
endpointStringCalled API endpoint, in this case: "upload".
codeIntegerMirror of the returned HTTP code.
errorStringError message.
timeFloatScript execution time, in seconds.

JavaScript Example:

await sharexen.upload(FILE).then(res => {
    if (res.err === false) {
        console.log(`Filename: ${res.filename}\nURL: ${res.url}\nDeletion Url: ${res.deletion_url}\n`);
    } else {
        console.error(res.error);
    }
});
  • The FILE is a link to a basic image or a local image URL.

Delete a File

The function "delete" returns either an error or the response from the ShareXen Server.

In case of classic response, the response will contain:

NameTypeDescription
errbooleanPresence of error ?
api_versionStringCurrent API version number (SemVer).
endpointStringCalled API endpoint, in this case: "delete".
codeIntegerMirror of the returned HTTP code.
filenameStringName of the file as stored on the server.
methodStringAuthentication method used to call the endpoint.
timeFloatScript execution time, in seconds.

In case of error, the response will contain:

NameTypeDescription
errbooleanPresence of error ?
endpointStringCalled API endpoint, in this case: "delete".
codeIntegerMirror of the returned HTTP code.
errorStringError message.
existsbooleanFile exist ?
timeFloatScript execution time, in seconds.

JavaScript Example:

await sharexen.delete(FILE).then(res => {
    if (res.err === false) {
        console.log(`Filename: ${res.filename}\nMethod: ${res.method}\n`);
    } else {
        console.error(res.error);
    }
});
  • The FILE is a link to the image or the name of the image stored on the server.

Rename a File

The function "rename" returns either an error or the response from the ShareXen Server.

In case of classic response, the response will contain:

NameTypeDescription
errbooleanPresence of error ?
api_versionStringCurrent API version number (SemVer).
endpointStringCalled API endpoint, in this case: "rename".
codeIntegerMirror of the returned HTTP code.
old_nameStringPrevious name of the file.
new_nameStringName of the file as stored on the server.
urlStringURL for the new file.
deletion_urlStringFull deletion URL for the new file.
keyStringSecurity key for the new file.
methodStringAuthentication method used to call the endpoint.
timeFloatScript execution time, in seconds.

In case of error, the response will contain:

NameTypeDescription
errbooleanPresence of error ?
endpointStringCalled API endpoint, in this case: "rename".
codeIntegerMirror of the returned HTTP code.
errorStringError message.
existsbooleanFile exist ?
timeFloatScript execution time, in seconds.

JavaScript Example:

await sharexen.rename(FILE, NEW_FILE_NAME).then(res => {
    if (res.err === false) {
        console.log(`Old Filename: ${res.old_name}\nNew Filename: ${res.new_name}`);
    } else {
        console.error(res.error);
    }
});
  • The FILE is a link to the image or the name of the image stored on the server.
  • The NEW_FILE_NAME is the new name you want to give to FILE.

Get informations on a file

The "info" function can return different things depending on the existence or not of the requested file (to retrieve information from a file).

In case of an existing file, the response will contain:

NameTypeDescription
errbooleanPresence of error ?
api_versionStringCurrent API version number (SemVer).
endpointStringCalled API endpoint, in this case: "info".
codeIntegerMirror of the returned HTTP code.
is_adminbooleanAdmin status of the caller.
filenameStringName of the file as stored on the server.
filesizeIntegerSize of the file in bytes.
urlStringURL for the new file.
deletion_urlString(User must be an administrator) Full deletion URL for the new file.
keyString(User must be an administrator) Security key for the new file.
existsbooleanFile exist ?
uploaded_timeIntegerFile upload timestamp.
timeFloatScript execution time, in seconds.

In case of a nonexisting file, the response will contain:

NameTypeDescription
errbooleanPresence of error ?
api_versionStringCurrent API version number (SemVer).
endpointStringCalled API endpoint, in this case: "info".
codeIntegerMirror of the returned HTTP code.
is_adminbooleanAdmin status of the caller.
existsbooleanFile exist ?
timeFloatScript execution time, in seconds.

In case of error, the response will contain:

NameTypeDescription
errbooleanPresence of error ?
api_versionStringCurrent API version number (SemVer).
endpointStringCalled API endpoint, in this case: "info".
codeIntegerMirror of the returned HTTP code.
errorStringError message.
timeFloatScript execution time, in seconds.

JavaScript Example:

await sharexen.info(FILE).then(res => {
    if (res.exists === true) {
        console.log(res.filename);
    } else {
        console.log(res.exists);
    }
});
  • The FILE is a link to the image or the name of the image stored on the server.

Obtain global information from the server used

The "info" function can return different things depending on the administration status of the user (to retrieve information from the server used).

NameTypeDescription
errbooleanPresence of error ?
api_versionStringCurrent API version number (SemVer).
endpointStringCalled API endpoint, in this case: "info".
codeIntegerMirror of the returned HTTP code.
is_adminbooleanAdmin status of the caller.
endpointsArray of StringsList of supported API endpoints.
keyspaceStringKeyspace used by the API.
name_lengthIntegerSize of random names.
allowed_extensionsArray of StringsList of allowed file extensions.
allowed_charactersStringAdditional allowed characters, for custom filenames.
custom_namesbooleanWhether custom filenames are globally allowed or not.
files_countIntegerAmount of files (matching allowed extensions) in the current folder.
filesArray of Strings(User must be an administrator) of files (matching allowed extensions) in the current folder.
timeFloatScript execution time, in seconds.

In case of error, the response will contain:

NameTypeDescription
errbooleanPresence of error ?
api_versionStringCurrent API version number (SemVer).
endpointStringCalled API endpoint, in this case: "info".
codeIntegerMirror of the returned HTTP code.
errorStringError message.
timeFloatScript execution time, in seconds.

JavaScript Example:

await sharexen.info(FILE).then(res => {
    if (res.err === false) {
        console.log(`I found ${res.files_count} files !`);
    } else {
        console.error(res.error);
    }
});