Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Node and Python examples to use respective APIs #102

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/public/assets/custom/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,7 @@
.am5-modal-content {
color: #000000 !important;
}

.tab-pane > p{
padding-top: 15px;
}
66 changes: 36 additions & 30 deletions src/public/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
<button class="nav-link active" id="curl-tab" data-bs-toggle="tab" data-bs-target="#curl-tab-pane" type="button" role="tab" aria-controls="curl-tab-pane" aria-selected="true">Curl</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="node-tab" data-bs-toggle="tab" data-bs-target="#node-tab-pane" type="button" role="tab" aria-controls="node-tab-pane" aria-selected="false">Node (node-fetch)</button>
<button class="nav-link" id="node-tab" data-bs-toggle="tab" data-bs-target="#node-tab-pane" type="button" role="tab" aria-controls="node-tab-pane" aria-selected="false">Node</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="go-tab" data-bs-toggle="tab" data-bs-target="#go-tab-pane" type="button" role="tab" aria-controls="go-tab-pane" aria-selected="false">Go</button>
Expand Down Expand Up @@ -218,27 +218,29 @@ curl --request PUT --url <%- process.env.BASE_URL; -%>/rest --header 'Content-Ty
</pre>
</div>
<div class="tab-pane fade" id="node-tab-pane" role="tabpanel" aria-labelledby="node-tab" tabindex="0">
<pre><code class="language-ts">
import fetch, {fileFrom, FormData} from 'node-fetch';
<p>For Node, there is an official SDK that provides access to all of the features of the site.</p>
<a class="btn btn-primary btn-sm mb-3" href="https://www.npmjs.com/package/waifuvault-node-api" target="_blank">WaifuVault Node API</a>
<pre><code class="language-ts">
import Waifuvault from "waifuvault-node-api";

// upload file
const formData = new FormData();
const blob = await fileFrom('./src/input.txt');
formData.set('file', blob);
const response = await fetch("<%- process.env.BASE_URL; -%>/rest", {
method: 'PUT',
body: formData
const resp = await Waifuvault.uploadFile({
file: "./files/aCoolFile.jpg"
});
const data = await response.json(); // object
console.log(resp.url); // the file download URL

// upload via URL
const encodedParams = new URLSearchParams();
encodedParams.set('url', 'https://victorique.moe/img/slider/Quotes.jpg');
const response = await fetch("<%- process.env.BASE_URL; -%>/rest", {
method: 'PUT',
body: encodedParams
const resp = await Waifuvault.uploadFile({
url: "https://waifuvault.moe/assets/custom/images/08.png"
});
const data = await response.json(); // object
console.log(resp.url); // the file download URL

// upload a buffer
const resp = await Waifuvault.uploadFile({
file: Buffer.from("someData"),
filename: "aCoolFile.jpg"
});
console.log(resp.url); // the file download URL
</code>
</pre>
</div>
Expand Down Expand Up @@ -303,25 +305,29 @@ func main() {
</pre>
</div>
<div class="tab-pane fade" id="python-tab-pane" role="tabpanel" aria-labelledby="python-tab" tabindex="0">
<p>For Python, there is an official SDK that provides access to all of the features of the site.</p>
<a class="btn btn-primary btn-sm mb-3" href="https://pypi.org/project/waifuvault/" target="_blank">WaifuVault Python API</a>
<pre><code class="language-python">
import requests
from requests_toolbelt import MultipartEncoder
import waifuvault
import io

# upload file
multipart_data = MultipartEncoder(
fields={
'file': ('input.txt', open('./src/input.txt', 'rb'), 'text/plain')
}
)
response = requests.put("<%- process.env.BASE_URL; -%>/rest", data=multipart_data, headers={'Content-Type': multipart_data.content_type})
data = response.json()
upload_file = waifuvault.FileUpload("./files/aCoolFile.png")
upload_res = waifuvault.upload_file(upload_file)
print(f"{upload_res.url}")

# upload via URL
response = requests.put(
"<%- process.env.BASE_URL; -%>/rest",
data={'url': 'https://victorique.moe/img/slider/Quotes.jpg'}
)
data = response.json()
upload_file = waifuvault.FileUpload("https://waifuvault.moe/assets/custom/images/08.png")
upload_res = waifuvault.upload_file(upload_file)
print(f"{upload_res.url}")

# upload a buffer
with open("./files/aCoolFile.png", "rb") as fh:
buf = io.BytesIO(fh.read())

upload_file = waifuvault.FileUpload(buf, "aCoolFile.png")
upload_res = waifuvault.upload_file(upload_file)
print(f"{upload_res.url}")
</code>
</pre>
</div>
Expand Down