Skip to content

Instantly share code, notes, and snippets.

View jirawatee's full-sized avatar
🔥
Better Together

Jirawat Karanwittayakarn jirawatee

🔥
Better Together
View GitHub Profile
@jirawatee
jirawatee / uploadPhoto.js
Created May 25, 2020 14:29
Resize image by Firebase Extensions - 4
let prefix = `https://firebasestorage.googleapis.com/v0/b/${bucket.name}/o`
let suffix = `alt=media&token=${uuid}`
return {
original: `${prefix}/${encodeURIComponent(file[0].name)}?${suffix}`,
thumb: `${prefix}/photos${encodeURIComponent(`/${event.source.userId}/thumbs/${event.timestamp}_200x200.jpg`)}?${suffix}`
}
@jirawatee
jirawatee / uploadPhoto.js
Created May 25, 2020 08:49
Resize image by Firebase Extensions - 0
const functions = require('firebase-functions')
const request = require('request-promise')
// สำหรับการเข้าถึง Cloud Storage
const admin = require('firebase-admin')
admin.initializeApp()
// สำหรับสร้าง public url ใน Cloud Storage
const UUID = require('uuid-v4')
@jirawatee
jirawatee / uploadPhoto.js
Created May 25, 2020 08:48
Resize image by Firebase Extensions - 3
const reply = (replyToken, payload) => {
request.post({
uri: `${LINE_MESSAGING_API}/message/reply`,
headers: LINE_HEADER,
body: JSON.stringify({
replyToken: replyToken,
messages: [payload]
})
})
}
@jirawatee
jirawatee / uploadPhoto.js
Created May 25, 2020 08:48
Resize image by Firebase Extensions - 3
const reply = (replyToken, payload) => {
request.post({
uri: `${LINE_MESSAGING_API}/message/reply`,
headers: LINE_HEADER,
body: JSON.stringify({
replyToken: replyToken,
messages: [payload]
})
})
}
@jirawatee
jirawatee / uploadPhoto.js
Last active May 25, 2020 09:43
Resize image by Firebase Extensions - 2
const upload = async (event) => {
// ดาวน์โหลด binary จาก LINE
const LINE_CONTENT_API = 'https://api-data.line.me/v2/bot/message'
let url = `${LINE_CONTENT_API}/${event.message.id}/content`
let buffer = await request.get({
headers: LINE_HEADER,
uri: url,
encoding: null // กำหนดเป็น null เพื่อให้ได้ binary ที่สมบูรณ์
})
@jirawatee
jirawatee / uploadPhoto.js
Last active May 25, 2020 08:35
Resize image by Firebase Extension - 1
exports.uploadPhoto = functions.https.onRequest(async (req, res) => {
let event = req.body.events[0]
if (event.type === 'message' && event.message.type === 'image') {
// เรียกฟังก์ชัน upload เมื่อเข้าเงื่อนไข
let urls = await upload(event)
// reply ตัว URL ที่ได้กลับไปยังห้องแชท
await reply(event.replyToken, { type: "text", text: urls })
}
})
@jirawatee
jirawatee / liff-login.html
Last active August 27, 2022 18:17
How to hack LIFF Login in external browser
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>LIFF - LINE Front-end Framework</title>
<style>
body { margin: 16px }
button, img { display: none; width: 40% }
button { padding: 16px }
@jirawatee
jirawatee / promise.js
Created March 18, 2020 07:03
Sample code how to request promises in parallel
const promiseA = () => new Promise(resolve => {
setTimeout(() => resolve("result of promiseA"), 2000)
})
const promiseB = () => new Promise(resolve => {
setTimeout(() => resolve("result of promiseB"), 3000)
})
const promiseC = () => new Promise(resolve => {
setTimeout(() => resolve("result of promiseC"), 1000)
})
@jirawatee
jirawatee / flex.json
Created March 6, 2020 10:20
Flex for community
{
"line": {
"type": "flex",
"altText": "LIFF",
"contents": {
"type": "carousel",
"contents": [
{
"type": "bubble",
"body": {
@jirawatee
jirawatee / index.html
Last active April 2, 2024 17:14
LIFF Share Target Picker
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0,viewport-fit=cover">
<title>My LIFF App</title>
<style>
body { padding: 256px }
button { display: none; width: 50%; padding: 16px 0; margin: 16px auto }
</style>