forked from kaimallea/node-imgur
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from KenEucker/develop
2.0.1
- Loading branch information
Showing
20 changed files
with
17,388 additions
and
3,395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ lib/ | |
src/coverage/ | ||
dist/ | ||
webpack.config.js | ||
example | ||
imgur.js | ||
imgur.node.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ src/coverage | |
*.code-workspace | ||
lib | ||
dist | ||
.DS_Store | ||
.DS_Store | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ lib/ | |
package-lock.json | ||
.github | ||
src/coverage/ | ||
example | ||
imgur.js | ||
imgur.node.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const env = { | ||
"CLIENT_ID": "YOUR-CLIENT-ID", | ||
"ACCESS_TOKEN": "YOUR-ACCESS-TOKEN", | ||
"ALBUM": "YOUR-ALBUM" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<html> | ||
|
||
<head> | ||
|
||
<meta charset="utf-8"> | ||
<meta type="title" content="Imgur API test"> | ||
<title>Imgur API test</title> | ||
<script src="../dist/imgur.js"></script> | ||
<script src="env.js"></script> | ||
|
||
</head> | ||
|
||
<body> | ||
|
||
<img id="image" src="" style="min-width: 25vw;" /> | ||
<video id="video" src="" controls></video> | ||
|
||
<div> | ||
<label for="uploadImage">Upload Image</label> | ||
<input id="uploadImage" type="file" rel="image"> | ||
<label for="uploadVideo">Upload Video</label> | ||
<input id="uploadVideo" type="file" rel="video"> | ||
</div> | ||
|
||
<script defer> | ||
const album = env.ALBUM; | ||
let client; | ||
|
||
const getImageStream = (img) => { | ||
const canvas = document.createElement("canvas") | ||
canvas.width = canvas.height = 100 | ||
const ctx = canvas.getContext("2d") | ||
ctx.drawImage(img, 0, 0) | ||
return canvas.toDataURL() | ||
} | ||
|
||
const upload = (e) => { | ||
const file = e.target.files.length ? e.target.files[0] : null | ||
const targetEl = document.getElementById(e.target.getAttribute('rel')) | ||
client.upload({ | ||
album, | ||
image: file, | ||
type: 'stream' | ||
}) | ||
.then((response) => { | ||
const r = response.length ? response[0] : response | ||
const i = r.success ? r.data : null | ||
if (i) { | ||
targetEl.src = i.link | ||
} | ||
}) | ||
} | ||
|
||
const init = () => { | ||
client = new imgur({ | ||
accessToken: env.ACCESS_TOKEN, | ||
clientId: env.CLIENT_ID, | ||
}) | ||
|
||
const uploadImageEl = document.getElementById('uploadImage') | ||
const uploadVideoEl = document.getElementById('uploadVideo') | ||
uploadImageEl.addEventListener('change', upload) | ||
uploadVideoEl.addEventListener('change', upload) | ||
} | ||
init() | ||
</script> | ||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const { ImgurClient } = require('../dist/imgur.node'); | ||
const { createReadStream } = require('fs'); | ||
const { join } = require('path'); | ||
require('dotenv').config(); | ||
|
||
const album = process.env.ALBUM; | ||
const imgur = new ImgurClient({ | ||
accessToken: process.env.ACCESS_TOKEN, | ||
clientId: process.env.CLIENT_ID, | ||
}); | ||
|
||
const imageStream = createReadStream(join(__dirname, 'small.jpg')); | ||
const videoStream = createReadStream(join(__dirname, 'small.mp4')); | ||
|
||
imgur.upload({ album, image: imageStream, type: 'stream' }).then(console.log); | ||
imgur.upload({ album, image: videoStream, type: 'stream' }).then(console.log); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Oops, something went wrong.