repl.it-api
Advanced tools
Comparing version 1.1.0 to 1.2.0
36
lib.js
@@ -43,2 +43,20 @@ const { CookieJar, Cookie } = require('tough-cookie') | ||
async loadFromPath(path) { | ||
const { id, url, fileNames, slug, language } = await this.fetch(`https://repl.it/data/repls/${path}`).then(parseJson) | ||
this.got.id = id | ||
this.got.url = url | ||
this.got.slug = slug | ||
this.got.language = language | ||
this.got.mainFile = fileNames[0] | ||
this.got.token = await this.fetch(`https://repl.it/data/repls/${id}/gen_repl_token`, { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
liveCodingToken: null, | ||
polygott: false | ||
}), | ||
headers | ||
}).then(parseJson) | ||
} | ||
login(sid) { | ||
@@ -103,2 +121,20 @@ const cookie = Cookie.fromJSON({ | ||
async read(name) { | ||
const json = await this.fetch(`https://repl.it/data/repls/signed_urls/${this.got.id}/${encodeURIComponent(name)}?d=${Date.now()}`).then(parseJson) | ||
const readUrl = json.urls_by_action.read | ||
const content = await this.fetch(readUrl, { | ||
method: 'GET' | ||
}).then((response) => response.text()) | ||
return content | ||
} | ||
readMain() { | ||
return this.read(this.got.mainFile) | ||
} | ||
async list() { | ||
const { fileNames } = await this.fetch(`https://repl.it/data/repls${this.got.url}`).then(parseJson) | ||
return fileNames | ||
} | ||
run(listeners = {}) { | ||
@@ -105,0 +141,0 @@ const { output, timedOut, listen, installStart, installOutput, installEnd } = listeners |
{ | ||
"name": "repl.it-api", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A Node.js client for creating projects and executing code on Repl.it.", | ||
@@ -5,0 +5,0 @@ "main": "lib.js", |
@@ -47,2 +47,14 @@ # Repl.it API | ||
### Load from a Path | ||
Instead of creating a new project, you may want to load an existing project. Currently we support loading from a path like `@User/Repl-Name`. | ||
```javascript | ||
await client.loadFromPath('@User/Repl-Name') | ||
``` | ||
`client#loadFromPath` takes one argument: a string that should be the file path. | ||
Also note that if you do not have write access to that project, you will only be able to read from files. | ||
### Write to a File | ||
@@ -67,2 +79,42 @@ | ||
### Read from a File | ||
```javascript | ||
const content = await client.read('file.js') | ||
``` | ||
You can also read from the main file. | ||
```javascript | ||
const content = await client.readMain() | ||
``` | ||
`client#read` takes one argument: a string that should be the filename. | ||
### List All Files | ||
You can also list all the files in a project. **Note that it'll return a flat array in a weird format!** Due to limitations of Google Cloud Storage, the file heirarchy is flattened. | ||
Say the file heirarchy *seems* like this: | ||
``` | ||
/ | ||
|-- index.js | ||
|-- lib/ | ||
| |-- blah.js | ||
| |-- other.js | ||
``` | ||
This is how it'll actually be stored: | ||
```javascript | ||
[ 'index.js', 'lib/blah.js', 'lib/other.js' ] | ||
``` | ||
Without further ado, below is the usage example. | ||
```javascript | ||
const files = await client.list() | ||
``` | ||
### Run the Project | ||
@@ -69,0 +121,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13723
203
179