From f9c4421d48b1a5bd3382f55a005fee82f83ab1e9 Mon Sep 17 00:00:00 2001 From: ilim Date: Sat, 8 Dec 2018 18:27:41 +0900 Subject: [PATCH] =?UTF-8?q?=E7=9F=AD=E7=B8=AEURL=E3=82=92=E5=87=BA?= =?UTF-8?q?=E5=8A=9B=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- caputure.js | 9 ++++----- photoAPI.js | 5 +++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/caputure.js b/caputure.js index 316eff1..4bfe986 100644 --- a/caputure.js +++ b/caputure.js @@ -23,10 +23,9 @@ const Webcam = NodeWebcam.create({ */ /** - * @param {OAuth2Client} oAuth2Client - * @returns {Promise} + * @param {OAuth2Client}oAuth2Client + * @param {Object} album */ - module.exports.capture = (oAuth2Client, album) => { return new Promise((resolve, reject) => { Webcam.capture("", async (err, photo) => { @@ -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)); }) }) }; @@ -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) { diff --git a/photoAPI.js b/photoAPI.js index dfcb21b..31a37c6 100644 --- a/photoAPI.js +++ b/photoAPI.js @@ -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();