initial
This commit is contained in:
commit
74ae93a96e
16 changed files with 94691 additions and 0 deletions
61
joplin notion extension/Web Development/API/Extras.md
Normal file
61
joplin notion extension/Web Development/API/Extras.md
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
Extras
|
||||
|
||||
1.
|
||||
2. - https://www.kvstore.io : key-value service 100 keys, 1kb/key.
|
||||
- https://internxt.com/ : e2e file storage from 2gb to 10gb
|
||||
- https://uploadcare.com : image hosting
|
||||
- https://developer.box.com/ : box.com api
|
||||
- https://blackvid.space/#api : api to display movies maybe
|
||||
- sentry2 : markdown previewer paste with sharable links
|
||||
- https://api.invidious.io/ : for invidious
|
||||
- https://martinheinz.dev/blog/113 : curl usage examples
|
||||
- https://github.com/LuanRT/BgUtils : utils to pass botguard and youtube attestation challenges
|
||||
- https://rclone.js.org/ : using rclone with nodejs
|
||||
- https://transfer.adminforge.de/
|
||||
`curl --upload-file ./hello.txt https://transfer.adminforge.de/hello.txt`
|
||||
using https://github.com/dutchcoders/transfer.sh
|
||||
|
||||
|
||||
using jsdom to parse js data
|
||||
```js
|
||||
const fetch=require('node-fetch');
|
||||
// import { JSDom } from "jsdom"
|
||||
const {JSDOM} = require("jsdom")
|
||||
|
||||
const url = 'https://www.mediafire.com/cdn-cgi/challenge-platform/scripts/jsd/main.js';
|
||||
const options = {method: 'GET'};
|
||||
|
||||
|
||||
async function main(){
|
||||
|
||||
try {
|
||||
const response = await fetch(url, options);
|
||||
const data = await response.text();
|
||||
// console.log(data);
|
||||
|
||||
|
||||
|
||||
const dom = new JSDOM()
|
||||
|
||||
global.window = dom.window
|
||||
global.document = dom.window.document
|
||||
|
||||
eval(data)
|
||||
|
||||
console.log(global.window)
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
```
|
||||
|
||||
|
||||
Others
|
||||
1. 0x0.st
|
||||
`curl -F'file=@yourfile.png' https://0x0.st`
|
||||
2. https://docs.filen.io/docs/api/specs/ : filen, 3 month temp storage
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
Reverse Engineering
|
||||
|
||||
- sdrive(Works only in nodejs due to CORS)
|
||||
|
||||
```jsx
|
||||
const fetch=require('node-fetch')
|
||||
const fs=require('fs')
|
||||
const FormData = require('form-data');
|
||||
const axios=require('axios')
|
||||
|
||||
const file=fs.readFileSync('image_icon.png')
|
||||
|
||||
const url='https://sdrive.app/publicapi/upload'
|
||||
|
||||
// const formData=new FormData()
|
||||
|
||||
// formData.append('file',file)
|
||||
|
||||
|
||||
// fetch(url,{
|
||||
// method: 'post',
|
||||
// body: file
|
||||
|
||||
// })
|
||||
// .then(res=>res.text())
|
||||
// .then(html=>{
|
||||
// fs.writeFileSync('content.html',html)
|
||||
// })
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('file', file, { filename: 'image_icon.png' }); // Specify the filename when appending the file
|
||||
|
||||
axios.post(url, formData, {
|
||||
headers: {
|
||||
...formData.getHeaders() // Include headers from FormData
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
console.log('File uploaded successfully:', response.data);
|
||||
// Handle the response data as needed
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
// Handle any errors that occurred during the upload
|
||||
});
|
||||
```
|
||||
9
joplin notion extension/Web Development/API/Rumble.md
Normal file
9
joplin notion extension/Web Development/API/Rumble.md
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
Rumble
|
||||
https://chatgpt.com/share/6853efa4-c3c9-4089-937e-f3ec1b02b4ab
|
||||
[rumble_api.txt](../../../_resources/rumble_api.txt)
|
||||
|
||||
|
||||
- To get access token
|
||||
https://stackoverflow.com/questions/78031116/how-to-get-access-token-for-rumble-api
|
||||
|
||||
when uploading
|
||||
76
joplin notion extension/Web Development/API/blackbaze.md
Normal file
76
joplin notion extension/Web Development/API/blackbaze.md
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
blackbaze
|
||||
https://www.backblaze.com/docs/cloud-storage-api-operations
|
||||
|
||||
**Note** : sharable link not available without adding credit card
|
||||
|
||||
### for downloading
|
||||
Blackblaze B2 operates with a different API than AWS S3, but downloading a file using a read access token is straightforward. To access files in a B2 bucket, you'll typically follow these steps for authorization and then proceed with downloading the desired file.
|
||||
Steps to Download a File from Backblaze B2
|
||||
|
||||
|
||||
Get Authorization Token: You'll need to authenticate against the B2 API to obtain an authorization token. This is generally done via an API call using your account's Application Key ID and Application Key.
|
||||
|
||||
Make a Download Request: Use the authorization token to make a request to download the file from the bucket.
|
||||
|
||||
Here are detailed steps:
|
||||
Step 1: Get Authorization Token
|
||||
|
||||
Use the following endpoint to get your authorization token:
|
||||
|
||||
Request:
|
||||
```bash
|
||||
curl -X GET "https://api.backblazeb2.com/b2_authorize_account" \
|
||||
-H "Authorization: Basic $(echo -n 'APPLICATION_KEY_ID:APPLICATION_KEY' | base64)"
|
||||
```
|
||||
Replace `APPLICATION_KEY_ID` and `APPLICATION_KEY` with your actual credentials.
|
||||
|
||||
Response:
|
||||
|
||||
This will return a JSON object containing your apiUrl, authorizationToken, and other details:
|
||||
|
||||
```json
|
||||
{
|
||||
"accountId": "some_account_id",
|
||||
"bucketId": "some_bucket_id",
|
||||
"bucketName": "your_bucket",
|
||||
"downloadUrl": "https://f002.backblazeb2.com",
|
||||
"authorizationToken": "your_authorization_token",
|
||||
...
|
||||
}
|
||||
```
|
||||
Step 2: Download the File
|
||||
|
||||
Once you have the downloadUrl and authorizationToken, you can download files stored in your B2 bucket. You'll need to format the URL correctly based on the file's path in the bucket.
|
||||
|
||||
Example cURL Command to Download File:
|
||||
|
||||
Assuming your download URL is https://f002.backblazeb2.com and you have the bucket name and file name:
|
||||
|
||||
`curl -L -o LOCAL_FILENAME "https://f002.backblazeb2.com/file/Bucket_Name/Path/To/Your/File.txt" \
|
||||
-H "Authorization: your_authorization_token"`
|
||||
|
||||
Example of the Full Process
|
||||
|
||||
Here’s a combined example of both steps in shell commands:
|
||||
```bash
|
||||
# Step 1: Get Authorization Token
|
||||
auth_response=$(curl -s -X GET "https://api.backblazeb2.com/b2_authorize_account" \
|
||||
-H "Authorization: Basic $(echo -n 'APPLICATION_KEY_ID:APPLICATION_KEY' | base64)")
|
||||
|
||||
# Extract the necessary fields using jq (install it if you don't have it)
|
||||
apiUrl=$(echo $auth_response | jq -r '.apiUrl')
|
||||
downloadUrl=$(echo $auth_response | jq -r '.downloadUrl')
|
||||
authToken=$(echo $auth_response | jq -r '.authorizationToken')
|
||||
|
||||
# Step 2: Download the file
|
||||
curl -L -o LOCAL_FILENAME "${downloadUrl}/file/YOUR_BUCKET_NAME/PATH/TO/YOUR/FILE.txt" \
|
||||
-H "Authorization: ${authToken}"
|
||||
```
|
||||
|
||||
Important Notes
|
||||
|
||||
Authorization: Make sure to replace APPLICATION_KEY_ID, APPLICATION_KEY, Your_Bucket_Name, and PATH/TO/YOUR/FILE.txt with your actual values.
|
||||
Token Validity: The authorization token will expire after a limited time, so you may need to call the authorization endpoint to get a new token if it has expired.
|
||||
Using Environment Variables: For security, consider storing sensitive credentials in environment variables instead of hardcoding them directly into your scripts.
|
||||
|
||||
With these steps, you should be able to easily download files from Backblaze B2 using your read access token!
|
||||
31
joplin notion extension/Web Development/API/catbox.md
Normal file
31
joplin notion extension/Web Development/API/catbox.md
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
catbox
|
||||
|
||||
- https://catbox.moe/tools.php
|
||||
- cURL to API
|
||||
If you want to make curl requests to the API, here are examples of both.
|
||||
`curl -F "reqtype=urlupload" -F "userhash=####" -F "url=https://files.catbox.moe/174bac.jpg" https://catbox.moe/user/api.php`
|
||||
|
||||
` curl -F "reqtype=fileupload" -F "userhash=####" -F "fileToUpload=@cutie.png" https://catbox.moe/user/api.php `
|
||||
|
||||
|
||||
Converting to axios
|
||||
```js
|
||||
import axios from 'axios';
|
||||
import FormData from 'form-data';
|
||||
import * as fs from 'fs';
|
||||
|
||||
const form = new FormData();
|
||||
form.append('reqtype', 'fileupload');
|
||||
form.append('userhash', '####');
|
||||
form.append('fileToUpload', fs.readFileSync('cutie.png'), 'cutie.png');
|
||||
|
||||
const response = await axios.post(
|
||||
'https://catbox.moe/user/api.php',
|
||||
form,
|
||||
{
|
||||
headers: {
|
||||
...form.getHeaders()
|
||||
}
|
||||
}
|
||||
);
|
||||
```
|
||||
43
joplin notion extension/Web Development/API/cloudinary.md
Normal file
43
joplin notion extension/Web Development/API/cloudinary.md
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
cloudinary
|
||||
https://cloudinary.com/documentation/upload_images
|
||||
`https://api.cloudinary.com/v1_1/<cloud name>/<resource_type>/upload`
|
||||
`cloud name` is the name of your Cloudinary product environment.
|
||||
`resource_type` is the type of file to upload. Valid values: image, raw, video and auto to automatically detect the file type.
|
||||
|
||||
for upload
|
||||
```bash
|
||||
curl --request POST \
|
||||
--url https://api.cloudinary.com/v1_1/cld-docs/auto/upload \
|
||||
--header 'content-type: multipart/form-data' \
|
||||
--form file=@path/to/file/sample.zip \
|
||||
--form api_key=<API_KEY> \
|
||||
--form upload_preset=ml_default
|
||||
```
|
||||
|
||||
response body
|
||||
```json
|
||||
{
|
||||
"asset_id": "3515c6000a548515f1134043f9785c2f",
|
||||
"public_id": "gotjephlnz2jgiu20zni",
|
||||
"version": 1719307544,
|
||||
"version_id": "7d2cc533bee9ff39f7da7414b61fce7e",
|
||||
"signature": "d0b1009e3271a942836c25756ce3e04d205bf754",
|
||||
"width": 1920,
|
||||
"height": 1441,
|
||||
"format": "jpg",
|
||||
"resource_type": "image",
|
||||
"created_at": "2024-06-25T09:25:44Z",
|
||||
"tags": [],
|
||||
"pages": 1,
|
||||
"bytes": 896838,
|
||||
"type": "upload",
|
||||
"etag": "2a2df1d2d2c3b675521e866599273083",
|
||||
"placeholder": false,
|
||||
"url": "http://res.cloudinary.com/cld-docs/image/upload/v1719307544/gotjephlnz2jgiu20zni.jpg",
|
||||
"secure_url": "https://res.cloudinary.com/cld-docs/image/upload/v1719307544/gotjephlnz2jgiu20zni.jpg",
|
||||
"asset_folder": "",
|
||||
"display_name": "gotjephlnz2jgiu20zni",
|
||||
"original_filename": "sample",
|
||||
"api_key": "614335564976464"
|
||||
}
|
||||
```
|
||||
36
joplin notion extension/Web Development/API/fileditch.md
Normal file
36
joplin notion extension/Web Development/API/fileditch.md
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
fileditch
|
||||
https://fileditch.com
|
||||
|
||||
- To upload
|
||||
To upload using curl or make a tool you can post using:
|
||||
`curl -i -F files[]=@yourfile.jpeg https://up1.fileditch.com/upload.php` (JSON Response)
|
||||
|
||||
Javascript(Browser)
|
||||
|
||||
```js
|
||||
const fileInput = document.getElementById('fileInput');
|
||||
|
||||
fileInput.addEventListener('change', async (event) => {
|
||||
const file = fileInput.files[0];
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('files[]', file);
|
||||
|
||||
fetch('https://up1.fileditch.com/upload.php', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.text();
|
||||
})
|
||||
.then((data) => {
|
||||
console.log('Upload successful:', data);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error during upload:', error);
|
||||
});
|
||||
})
|
||||
```
|
||||
61
joplin notion extension/Web Development/API/genius.md
Normal file
61
joplin notion extension/Web Development/API/genius.md
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
genius
|
||||
|
||||
|
||||
```js
|
||||
|
||||
const {parse}=require('node-html-parser')
|
||||
const fetch= require('node-fetch')
|
||||
|
||||
async function fetchLyricsFromLink(lyricUrl){
|
||||
const lyricContainerSelector= 'div[data-lyrics-container="true"]'
|
||||
|
||||
// const htmlString= fs.readFileSync('lyrics.html')
|
||||
|
||||
|
||||
const res= await fetch('https://genius.com/Green-day-the-american-dream-is-killing-me-lyrics')
|
||||
const htmlString= await res.text();
|
||||
|
||||
// const htmlString= `<div>
|
||||
// <div id="lis">
|
||||
// <ul>
|
||||
// <li>first</li>
|
||||
// <li>second</li>
|
||||
// </ul>
|
||||
// </div>
|
||||
// </div>`
|
||||
|
||||
const root = parse(htmlString)
|
||||
|
||||
// const obj=root.querySelector(lyricContainerSelector)
|
||||
const arr=root.querySelectorAll(lyricContainerSelector)
|
||||
|
||||
|
||||
// console.log(obj.outerHTML)
|
||||
|
||||
let str=""
|
||||
|
||||
for(let element of arr){
|
||||
// statements
|
||||
str+=element.textContent
|
||||
str+='\n'
|
||||
|
||||
}
|
||||
|
||||
return str;
|
||||
|
||||
// fs.writeFileSync('parsed_lyrics.html',str)
|
||||
|
||||
|
||||
}
|
||||
|
||||
fetch('https://genius.com/api/search/multi?per_page=5&q=Faith --Weeknd')
|
||||
.then(res=>res.json())
|
||||
.then(async(data)=>{
|
||||
const url= data.response.sections[0].hits[0].result.url
|
||||
console.log('url: ',url)
|
||||
const lyrics= await fetchLyricsFromLink(url)
|
||||
console.log('lyrics: ',lyrics)
|
||||
})
|
||||
.catch(console.log)
|
||||
|
||||
```
|
||||
14
joplin notion extension/Web Development/API/mediafire.md
Normal file
14
joplin notion extension/Web Development/API/mediafire.md
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
mediafire
|
||||
|
||||
- https://www.mediafire.com/developers/ : not anymore
|
||||
|
||||
|
||||
## Steps
|
||||
1. Get a session token. Note : Session token will be expired after a couple period of time so is cookie so need to generate them again, means somehow automate login.
|
||||
2. Using it to get folders and files info of root directory
|
||||
for folder and files content 2 api api is called and eveyrthing is same in request body except content-type
|
||||
request body is of form-data, files one will give the sharable link too
|
||||
folderkey field contains key of parent folder, root one is basically 'myfiles'.
|
||||
3. for uploadfile, it will check the folder where it is uploaded and quickkey of folder will be there too in response, then it will upload as `application/octlet-stream`, and will send filehash too in headers which is of `sha256sum`. After the resulable upload api, key will be get which will be used for next poll upload thing
|
||||
|
||||
4. for getting sharable link : : "https://www.mediafire.com/file/7mpw92w27etlaex/Restfox-main.zip/file" . so format is `https://www.mediafire.com/file/<quick_key>/<filename>/file` or just until quick_key is enough too
|
||||
39
joplin notion extension/Web Development/API/nextcloud.md
Normal file
39
joplin notion extension/Web Development/API/nextcloud.md
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
nextcloud
|
||||
|
||||
upload file
|
||||
https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/basic.html#uploading-files
|
||||
```bash
|
||||
curl -u username:password \
|
||||
--request PUT \
|
||||
--url https://nextcloud-fi.webo.hosting/remote.php/dav/files/<user_name>/alternative-front-ends-main.zip \
|
||||
--header 'content-type: application/octet-stream' \
|
||||
--data-binary @path/to/your/local/file
|
||||
```
|
||||
|
||||
|
||||
generating sharable link
|
||||
https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-share-api.html
|
||||
|
||||
- auth
|
||||
`curl -u username:password -X GET 'https://cloud.example.com/ocs/v1.php/...' -H "OCS-APIRequest: true"`
|
||||
|
||||
- get shareable items list
|
||||
`curl -u username:password -X GET 'https://cloud.example.com/ocs/v1.php/shares' -H "OCS-APIRequest: true"`
|
||||
- create sharable link
|
||||
```bash
|
||||
curl -u username:password --request POST \
|
||||
--url https://nextcloud-fi.webo.hosting/ocs/v2.php/apps/files_sharing/api/v1/shares \
|
||||
--header 'content-type: application/x-www-form-urlencoded' \
|
||||
--header 'ocs-apirequest: true' \
|
||||
--data path=/Photos/Birdie.jpg \
|
||||
--data shareType=3
|
||||
```
|
||||
|
||||
for nodejs fetch, -u username:password needs to be converted into basic auth header so convert `username:password` string to base64 and pass it header as `authorization: Basic <base64_version>`
|
||||
- upload file
|
||||
```bash
|
||||
curl -u username:password --request PUT \
|
||||
--url https://nextcloud-fi.webo.hosting/remote.php/dav/files/<username>/alternative-front-ends-main.zip \
|
||||
--header 'content-type: application/octet-stream' \
|
||||
--data-binary @path/to/your/local/file.zip
|
||||
```
|
||||
5
joplin notion extension/Web Development/API/pastebin.md
Normal file
5
joplin notion extension/Web Development/API/pastebin.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
pastebin
|
||||
|
||||
- With curl
|
||||
`curl -X POST -d 'api_dev_key=YOUR API DEVELOPER KEY' -d 'api_paste_code=test' -d 'api_option=paste' "https://pastebin.com/api/api_post.php"`
|
||||
|
||||
58
joplin notion extension/Web Development/API/sdrive.md
Normal file
58
joplin notion extension/Web Development/API/sdrive.md
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
sdrive(do not work in client side)
|
||||
|
||||
```jsx
|
||||
import axios from "axios";
|
||||
import FormData from "form-data";
|
||||
import fs from "fs";
|
||||
import dotenv from "dotenv";
|
||||
import mime from "mime-types";
|
||||
import path from "path";
|
||||
dotenv.config();
|
||||
async function uploadFile(fileStream, filename) {
|
||||
let formData = new FormData();
|
||||
let apikey = process.env.apikey;
|
||||
let base_url = process.env.base_url || "https://v3.sdrive.app";
|
||||
if (!apikey) {
|
||||
console.log("Please add your credentials to the .env file");
|
||||
process.exit();
|
||||
}
|
||||
|
||||
let mimetype = mime.lookup(path.extname(filename));
|
||||
formData.append("fileupload", fileStream, {
|
||||
filename: filename,
|
||||
contentType: mimetype,
|
||||
});
|
||||
formData.append("apikey", apikey);
|
||||
formData.append("network", "shdwdrive");
|
||||
|
||||
return await axios
|
||||
.post(base_url + "/upload", formData, {
|
||||
headers: formData.getHeaders(), // Set headers from formData
|
||||
})
|
||||
.catch((error) => {
|
||||
const errorInfo = {
|
||||
status: error.response.status,
|
||||
statusText: error.response.statusText,
|
||||
data: error.response.data,
|
||||
};
|
||||
throw Error(JSON.stringify(errorInfo));
|
||||
})
|
||||
.then((response) => {
|
||||
return response.data;
|
||||
});
|
||||
}
|
||||
|
||||
// Example usage
|
||||
(async () => {
|
||||
const inputPath = process.argv[2];
|
||||
const filename = inputPath.split("/").pop();
|
||||
const fileStream = fs.createReadStream(inputPath);
|
||||
try {
|
||||
const response = await uploadFile(fileStream, inputPath);
|
||||
console.log(response);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
sentry2 (stellar)
|
||||
|
||||
```js
|
||||
const fetch=require('node-fetch')
|
||||
|
||||
// const baseurl='https://rentry.co'
|
||||
const baseurl='https://sentrytwo.com'
|
||||
|
||||
const fetchurl=`${baseurl}/api/new`
|
||||
|
||||
const jsbody={
|
||||
content : 'this is text',
|
||||
custom_url : '',
|
||||
edit_password: 'secret',
|
||||
|
||||
}
|
||||
|
||||
const requestBody = new URLSearchParams(jsbody);
|
||||
|
||||
const csrfToken='R1ukF9nRyNITFeftszagNiM5g2izx0UtfNkPOIwurFqtVP63L00pQh1ahD6dmfj5' // for rentry, epire in 2025
|
||||
|
||||
fetch(fetchurl,{
|
||||
method : 'POST',
|
||||
headers: {
|
||||
// 'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Content-Type': 'application/json',
|
||||
// "Referer": 'https://rentry.co',
|
||||
// 'X-CSRF-Token': csrfToken,
|
||||
},
|
||||
body : JSON.stringify(jsbody)
|
||||
})
|
||||
.then(res=>res.text())
|
||||
.then(data=>{
|
||||
console.log('data: ',data)
|
||||
})
|
||||
.catch(err=>{
|
||||
console.log('err: ',err)
|
||||
})
|
||||
|
||||
```
|
||||
127
joplin notion extension/Web Development/API/sirv.md
Normal file
127
joplin notion extension/Web Development/API/sirv.md
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
sirv(500 mb storage)
|
||||
|
||||
- https://apidocs.sirv.com
|
||||
|
||||
nodejs
|
||||
```jsx
|
||||
const http = require("https");
|
||||
|
||||
|
||||
|
||||
const options = {
|
||||
"method": "POST",
|
||||
"hostname": "api.sirv.com",
|
||||
"port": null,
|
||||
"path": "/v2/token",
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"authorization": "Bearer BEARER_TOKEN_HERE"
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const req = http.request(options, function (res) {
|
||||
const chunks = [];
|
||||
|
||||
|
||||
res.on("data", function (chunk) {
|
||||
chunks.push(chunk);
|
||||
});
|
||||
|
||||
|
||||
res.on("end", function () {
|
||||
const body = Buffer.concat(chunks);
|
||||
console.log(body.toString());
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
req.write("{\"clientId\":\"ZcnZNfzwRhQExoHFoGpxWJ4p2R\",\"clientSecret\":\"TM3d0CfXxusKMpH3x7kHJYD40qJIR3omTIGXP6wPPkXpIUKLEz/dOJ9v6LbXra3y67XsaGK7iQPmnAuD+fzj+Q==\"}");
|
||||
req.end();
|
||||
|
||||
```
|
||||
|
||||
|
||||
Javascript(Vanilla)
|
||||
```jsx
|
||||
const data = "{\"clientId\":\"ZcnZNfzwRhQExoHFoGpxWJ4p2R\",\"clientSecret\":\"TM3d0CfXxusKMpH3x7kHJYD40qJIR3omTIGXP6wPPkXpIUKLEz/dOJ9v6LbXra3y67XsaGK7iQPmnAuD+fzj+Q==\"}";
|
||||
|
||||
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.withCredentials = true;
|
||||
|
||||
|
||||
xhr.addEventListener("readystatechange", function () {
|
||||
if (this.readyState === this.DONE) {
|
||||
console.log(this.responseText);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
xhr.open("POST", "https://api.sirv.com/v2/token");
|
||||
xhr.setRequestHeader("content-type", "application/json");
|
||||
xhr.setRequestHeader("authorization", "Bearer BEARER_TOKEN_HERE");
|
||||
|
||||
|
||||
xhr.send(data);
|
||||
|
||||
```
|
||||
|
||||
to upload file with curl
|
||||
```bash
|
||||
curl --request POST \
|
||||
--url 'https://api.sirv.com/v2/files/upload?filename=%2FREST%20API%20Examples%2Fuploaded.txt' \
|
||||
--header 'authorization: Bearer BEARER_TOKEN_HERE' \
|
||||
--header 'content-type: application/octet-stream' \
|
||||
--data-binary @path/to/your/local/file.txt
|
||||
```
|
||||
|
||||
with nodejs
|
||||
```js
|
||||
const fetch = require("node-fetch");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const uploadFile = async () => {
|
||||
try {
|
||||
// Replace with your own details
|
||||
const apiURL = "https://api.sirv.com/v2/files/upload?filename=%2FREST%20API%20Examples%2Fuploaded.txt";
|
||||
const token = "BEARER_TOKEN_HERE";
|
||||
const filePath = path.join(__dirname, "your-local-file.txt"); // Path to your local file
|
||||
|
||||
// Read the file as binary data
|
||||
const fileStream = fs.createReadStream(filePath);
|
||||
|
||||
// Make the POST request with binary data
|
||||
const response = await fetch(apiURL, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "application/octet-stream", // Appropriate content-type for binary file uploads
|
||||
},
|
||||
body: fileStream, // Use the file stream as the request body
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
console.log("File uploaded successfully:", data);
|
||||
} else {
|
||||
const error = await response.text();
|
||||
console.error("Error uploading file:", error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error uploading file:", error.message);
|
||||
}
|
||||
};
|
||||
|
||||
// Start the file upload
|
||||
uploadFile();
|
||||
```
|
||||
|
||||
sharable link format
|
||||
https://platletinvt.sirv.com/Images/Apple%20Watch%20white.jpg
|
||||
where this jpg file is in Images folder
|
||||
platletinvt is username
|
||||
Images is folder name
|
||||
rest is filename
|
||||
48
joplin notion extension/Web Development/API/tastedive.md
Normal file
48
joplin notion extension/Web Development/API/tastedive.md
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
tastedive
|
||||
|
||||
nodejs
|
||||
```js
|
||||
const fetch= require('node-fetch')
|
||||
|
||||
const getSimilarMovies=async(input)=>{
|
||||
|
||||
|
||||
// const input="batman"
|
||||
const searchurl=`https://tastedive.com/api/search?query=${input}&take=9&page=1&searchCategory=default&types=urn:entity:artist,urn:entity:movie,urn:entity:tv_show,urn:entity:book,urn:entity:videogame,urn:entity:podcast,urn:entity:person,urn:entity:place,urn:entity:brand`
|
||||
|
||||
|
||||
try{
|
||||
|
||||
const searchres=await fetch(searchurl)
|
||||
const searchdata= await searchres.json()
|
||||
|
||||
// console.log('data :', searchdata)
|
||||
|
||||
const entityID=searchdata.results?.[0]?.entity_id
|
||||
|
||||
if(entityID){
|
||||
const similarurl= `https://tastedive.com/api/getRecsByCategory?page=1&entityId=${entityID}&category=movies&limit=18`
|
||||
const similarRes = await fetch(similarurl)
|
||||
const similarData= await similarRes.json()
|
||||
|
||||
console.log('similarData: ',similarData)
|
||||
|
||||
return similarData
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
console.log('no entity_id')
|
||||
}
|
||||
}
|
||||
|
||||
catch(err){
|
||||
|
||||
// console.log('err: ', err)
|
||||
throw new Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports={getSimilarMovies}
|
||||
```
|
||||
83
joplin notion extension/Web Development/API/uploadcare.md
Normal file
83
joplin notion extension/Web Development/API/uploadcare.md
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
uploadcare
|
||||
|
||||
javascript(vanilla)
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<input type="file" name="" id=""><br>
|
||||
<button>Upload</button>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.6.7/axios.min.js" integrity="sha512-NQfB/bDaB8kaSXF8E77JjhHG5PM6XVRxvHzkZiwl3ddWCEPBa23T76MuWSwAJdMGJnmQqM0VeY9kFszsrBEFrQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
<script>
|
||||
const url='https://upload.uploadcare.com/base/'
|
||||
const pub_key='b182e75f948ada5a015f'
|
||||
|
||||
|
||||
const fileEle=document.querySelector("input")
|
||||
const button=document.querySelector("button")
|
||||
|
||||
const formdata= new FormData()
|
||||
button.addEventListener("click",()=>{
|
||||
const file=fileEle.files[0];
|
||||
console.log('file: ',file)
|
||||
formdata.append("UPLOADCARE_PUB_KEY",pub_key)
|
||||
// formdata.append("my_file.jpg",file)
|
||||
formdata.append("my_file.jpg",file)
|
||||
|
||||
axios.post(url, formdata, {
|
||||
|
||||
})
|
||||
.then(response => {
|
||||
console.log(response.data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
// fetch(url,{
|
||||
// method: 'POST',
|
||||
// headers: {
|
||||
// "Content-Type": "multipart/form-data"
|
||||
// },
|
||||
// body: formdata,
|
||||
// })
|
||||
// .then(res=>res.json())
|
||||
// .then(data=>{
|
||||
// console.log('data: ',data)
|
||||
|
||||
// })
|
||||
// .catch(err=>{
|
||||
// console.log('err: ',err)
|
||||
// console.log('err message: ',err.message)
|
||||
// })
|
||||
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
```
|
||||
|
||||
or with fetch
|
||||
```js
|
||||
fetch(url,{
|
||||
method: 'POST',
|
||||
|
||||
body: formdata,
|
||||
})
|
||||
.then(res=>res.json())
|
||||
.then(data=>{
|
||||
console.log('data: ',data)
|
||||
|
||||
})
|
||||
.catch(err=>{
|
||||
console.log('err: ',err)
|
||||
console.log('err message: ',err.message)
|
||||
})
|
||||
```
|
||||
Loading…
Reference in a new issue