This repository has been archived by the owner on Apr 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apis): add new apis for the images in repository
- Loading branch information
Kamontat Chantrachirathumrong
committed
Dec 27, 2018
1 parent
4d5249a
commit 9d6c165
Showing
9 changed files
with
190 additions
and
36 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
/.netlify/functions/* /v2/:splat 200! |
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,77 @@ | ||
const repo_owner = "kcnt-info"; | ||
const repo_name = "website"; | ||
const branch = "master"; | ||
const language = 'en' | ||
|
||
export const Information = { | ||
owner: repo_owner, | ||
repo: repo_name, | ||
branch: branch | ||
}; | ||
|
||
/** | ||
* generate github link to query result | ||
* @param {String} path path from root folder | ||
* @param {Object} opts options | ||
* @param {String} opts.branch branch of result | ||
*/ | ||
export const GenerateGithubLink = (path, opts = {}) => { | ||
const link = `https://raw.githubusercontent.com/${repo_owner}/${repo_name}/${opts.branch || | ||
branch}/static/resources/${path}`; | ||
console.log(`query to: ${link}`); | ||
return link | ||
} | ||
|
||
/** | ||
* get api link of information file | ||
* @param {String} user username, should be `net` or `prang` | ||
* @param {Object} opts options | ||
* @param {String} opts.branch branch of result | ||
* @param {String} opts.language language of the result | ||
*/ | ||
export const PersonalInformationLink = (user, opts = {}) => { | ||
return GenerateGithubLink(`${user}/personal/information-${opts.language || language}.json`, opts) | ||
}; | ||
|
||
/** | ||
* get api link of social file | ||
* @param {String} user username, should be `net` or `prang` | ||
* @param {Object} opts options | ||
* @param {String} opts.branch branch of result | ||
*/ | ||
export const PersonalSocialLink = (user, opts = {}) => { | ||
return GenerateGithubLink(`${user}/personal/social.json`, opts) | ||
}; | ||
|
||
export const _logoPNGLink = (color, opts = {}) => { | ||
let postfix = ''; | ||
let size = '1x'; | ||
if (opts.size === "small") { | ||
size = '0.5x' | ||
} else if (opts.size === "high") { | ||
size = "300ppi" | ||
postfix = '-high' | ||
} | ||
|
||
const type = opts.type === "round" ? "-round-icon" : '-icon' | ||
|
||
// https://raw.githubusercontent.com/kcnt-info/website/dev/static/resources/images/icon/1x/dark-icon.png | ||
return GenerateGithubLink(`images/icon/${size}/${color}${type}${postfix}.png`, opts) | ||
} | ||
|
||
export const _logoSVGLink = (color, type, opts = {}) => { | ||
const postfix = type === "round" ? "-round-icon" : '-icon' | ||
// https://raw.githubusercontent.com/kcnt-info/website/dev/static/resources/images/icon/SVG/dark-icon.svg | ||
return GenerateGithubLink(`images/icon/SVG/${color}${postfix}.svg`, opts) | ||
} | ||
|
||
/** | ||
* get api link of social file | ||
* @param {String} user username, should be `net` or `prang` | ||
* @param {Object} opts options | ||
* @param {String} opts.branch branch of result | ||
*/ | ||
export const LogoLink = (color, opts = {}) => { | ||
if (opts.extension === "png") return _logoPNGLink(color, opts); | ||
else return _logoSVGLink(color, opts.type, opts) | ||
} |
This file was deleted.
Oops, something went wrong.
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,39 @@ | ||
const matchPath = (path, results) => { | ||
const index = results.findIndex(p => path.includes(`/${p}`)) | ||
if (index < 0) return undefined; | ||
return results[index] | ||
} | ||
|
||
const matchQuery = (query, options) => { | ||
if (options === undefined) return query; | ||
return options.includes(query) ? query : undefined | ||
} | ||
|
||
/** | ||
* | ||
* @param {String} name name of the key result and query name | ||
* @param {Array<String>} options possible values | ||
* @param {String} defaultValue default value if value is not exist | ||
*/ | ||
export const GenObj = (name, options, | ||
defaultValue = undefined) => { | ||
if ( | ||
defaultValue === undefined || | ||
defaultValue === null) defaultValue = options[0] | ||
|
||
return { | ||
name: name, | ||
default: defaultValue, | ||
options: options | ||
} | ||
} | ||
|
||
export const ParseParameters = (event, ...obj) => { | ||
const query = event.queryStringParameters; | ||
const path = event.path; | ||
const result = {}; | ||
obj.forEach(v => { | ||
result[v.name] = matchPath(path, v.options) || matchQuery(query[v.name], v.options) || v.default | ||
}) | ||
return result | ||
} |
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,42 @@ | ||
const axios = require("axios") | ||
|
||
const { | ||
ParseParameters, | ||
GenObj | ||
} = require('../../lib/parseUrl') | ||
|
||
const { | ||
LogoLink | ||
} = require("../../lib/ghLink"); | ||
|
||
exports.handler = function (event, context, callback) { | ||
const result = ParseParameters(event, | ||
GenObj("branch", ["master", "dev"]), | ||
GenObj("color", ["primary", "light", "dark"]), | ||
GenObj("size", ["normal", "smaller", "high"]), | ||
GenObj("type", ["normal", "round"]), | ||
GenObj("extension", ["png", "svg"])) | ||
|
||
const url = LogoLink(result.color, result); | ||
|
||
axios | ||
.get(url, { | ||
responseType: 'arraybuffer' | ||
}) | ||
.then(response => { | ||
let image = Buffer.from(response.data, 'binary').toString('base64') | ||
|
||
callback(undefined, { | ||
statusCode: response.status, | ||
headers: { | ||
"Content-Type": result.extension === "svg" ? "image/svg+xml" : "image/png", | ||
"Content-Length": response.headers['content-length'], | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Headers": "*" | ||
}, | ||
body: image, | ||
isBase64Encoded: true | ||
}); | ||
}) | ||
.catch(callback); | ||
} |
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 @@ | ||
// TODO: Changes doc generate to https://github.com/danielgtaylor/aglio |