forked from viktorstrate/embassyos-photoview-wrapper
-
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
Showing
3 changed files
with
56 additions
and
2 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 |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from "https://deno.land/x/embassyd_sdk@v0.3.1.1.4/mod.ts"; | ||
export * from "https://deno.land/x/embassyd_sdk@v0.3.3.0.4/mod.ts"; | ||
export * from "https://deno.land/x/embassyd_sdk@v0.3.3.0.4/util.ts"; | ||
export * from "https://deno.land/x/embassyd_sdk@v0.3.3.0.4/healthUtil.ts"; |
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,52 @@ | ||
import { types as T, checkWebUrl, catchError } from "../deps.ts"; | ||
|
||
export const health: T.ExpectedExports.health = { | ||
// deno-lint-ignore require-await | ||
async "interface"(effects, duration) { | ||
// Checks that the server is running and reachable via http | ||
return healthWeb(effects, duration); | ||
}, | ||
// deno-lint-ignore require-await | ||
async "database"(effects, duration) { | ||
// Checks that the backend is reachable via graphQL | ||
return healthApi(effects, duration); | ||
}, | ||
}; | ||
|
||
// deno-lint-ignore require-await | ||
const healthWeb: T.ExpectedExports.health[""] = async (effects, duration) => { | ||
return checkWebUrl("http://photoview.embassy")(effects, duration).catch(catchError(effects)) | ||
}; | ||
|
||
const healthApi: T.ExpectedExports.health[""] = async (effects, duration) => { | ||
await guardDurationAboveMinimum({ duration, minimumTime: 15000 }); | ||
|
||
return effects.fetch("http://photoview.embassy:80/api/graphql", { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({"operationName":"CheckInitialSetup","variables":{},"query":"query CheckInitialSetup { siteInfo { initialSetup }}"}) | ||
}) | ||
.then((_) => ok) | ||
.catch((e) => { | ||
effects.error(`${e}`) | ||
return error(`The Photoview API is unreachable`) | ||
}); | ||
}; | ||
|
||
// *** HELPER FUNCTIONS *** // | ||
|
||
// Ensure the starting duration is pass a minimum | ||
const guardDurationAboveMinimum = ( | ||
input: { duration: number; minimumTime: number }, | ||
) => | ||
(input.duration <= input.minimumTime) | ||
? Promise.reject(errorCode(60, "Starting")) | ||
: null; | ||
|
||
const errorCode = (code: number, error: string) => ({ | ||
"error-code": [code, error] as const, | ||
}); | ||
const error = (error: string) => ({ error }); | ||
const ok = { result: null }; |