-
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.
- Loading branch information
1 parent
eab556d
commit 338ffcc
Showing
6 changed files
with
9 additions
and
51 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
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 |
---|---|---|
@@ -1,26 +1,11 @@ | ||
import jsSHA from 'jssha' | ||
import { TDXAPIParameters } from './types' | ||
|
||
export const getAuthorizationHeader = () => { | ||
const UTCTime = new Date().toUTCString() | ||
const ShaObj = new jsSHA('SHA-1', 'TEXT') | ||
ShaObj.setHMACKey(process.env.REACT_APP_TDX_APP_KEY || '', 'TEXT') | ||
ShaObj.update('x-date: ' + UTCTime) | ||
let HMAC = ShaObj.getHMAC('B64') | ||
let Authorization = 'hmac username="' + process.env.REACT_APP_TDX_APP_ID + '", algorithm="hmac-sha1", headers="x-date", signature="' + HMAC + '"' | ||
return { | ||
Authorization, | ||
'X-Date': UTCTime | ||
} | ||
} | ||
|
||
// Force to have `Name` and `Picture.PictureUrl1` fields | ||
export const getPathWithQueryString = (path: string, { limit = 600, keywords, city }: TDXAPIParameters, nameField: string) => { | ||
const filter = `Picture/PictureUrl1 ne null and ${nameField} ne null${ | ||
keywords | ||
const filter = `Picture/PictureUrl1 ne null and ${nameField} ne null${keywords | ||
? ` and (contains(${nameField}, '${keywords}') or contains(Description, '${keywords}'))` | ||
: "" | ||
}`; | ||
}`; | ||
const top = `&$top=${limit}` | ||
return `${path}${city ? '/' + city : ''}?$filter=${filter}${top}&$format=JSON` | ||
} |
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
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