Skip to content

Commit

Permalink
短縮URLを出力できるように
Browse files Browse the repository at this point in the history
  • Loading branch information
ilim0t committed Dec 8, 2018
1 parent 594d0d9 commit f9c4421
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 4 additions & 5 deletions caputure.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ const Webcam = NodeWebcam.create({
*/

/**
* @param {OAuth2Client} oAuth2Client
* @returns {Promise<void>}
* @param {OAuth2Client}oAuth2Client
* @param {Object} album
*/

module.exports.capture = (oAuth2Client, album) => {
return new Promise((resolve, reject) => {
Webcam.capture("", async (err, photo) => {
Expand All @@ -36,7 +35,7 @@ module.exports.capture = (oAuth2Client, album) => {
const uploadToken = await photoapi.uploadPhoto(oAuth2Client, photo, Date().toLocaleString());
const {mediaItem} = await photoapi.createAlbumMediaItem(oAuth2Client, album.id, uploadToken, "");
const {baseUrl} = await photoapi.getMediaItem(oAuth2Client, mediaItem.id);
resolve(baseUrl);
resolve(photoapi.getShortURL(baseUrl));
})
})
};
Expand All @@ -51,7 +50,7 @@ async function main() {
album = await photoapi.createAlbum(oAuth2Client, albumTitle);
await photoapi.shareAlbum(oAuth2Client, album.id);
}
setInterval(() => module.exports.capture(oAuth2Client, album).then(slack.send), 3000);
setInterval(() => module.exports.capture(oAuth2Client, album).then(slack.send), 5000);
}

if (require.main === module) {
Expand Down
5 changes: 5 additions & 0 deletions photoAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ module.exports.getMediaItem = async (oAuth2Client, mediaItemID) => {
});
};

module.exports.getShortURL = async url => {
const ret = await rpap.get(`http://is.gd/create.php?format=simple&format=json&url=${url}`);
return JSON.parse(ret)["shorturl"];
};

async function main() {
const oAuth2Client = await module.exports.getOAuthToken();

Expand Down

0 comments on commit f9c4421

Please sign in to comment.