Adding an ops tool to look at photographs
This commit is contained in:
@@ -7,25 +7,25 @@ export const config = {
|
|||||||
googleGeocodeAPIKey: "AIzaSyCs4JVT6gysnY5dAJ7KjVJYeykLv_xz1GI",
|
googleGeocodeAPIKey: "AIzaSyCs4JVT6gysnY5dAJ7KjVJYeykLv_xz1GI",
|
||||||
googleGeocodeURL: "https://maps.googleapis.com/maps/api/geocode/json",
|
googleGeocodeURL: "https://maps.googleapis.com/maps/api/geocode/json",
|
||||||
refererURL: "https://dar.kss.us.com",
|
refererURL: "https://dar.kss.us.com",
|
||||||
defaultUser: "john@lyon-smith.org",
|
//defaultUser: "john@lyon-smith.org",
|
||||||
//defaultUser: "",
|
defaultUser: "",
|
||||||
minGPSAccuracy: 100,
|
minGPSAccuracy: 100,
|
||||||
//minGPSAccuracy: 20,
|
//minGPSAccuracy: 20,
|
||||||
minDistanceToItem: 10,
|
minDistanceToItem: 10,
|
||||||
geocodeDelayMilliseconds: 500,
|
geocodeDelayMilliseconds: 500,
|
||||||
// This region is downtown Toronto
|
// This region is downtown Toronto
|
||||||
// initialRegion: {
|
|
||||||
// latitude: 43.653908,
|
|
||||||
// longitude: -79.384293,
|
|
||||||
// latitudeDelta: 0.0922,
|
|
||||||
// longitudeDelta: 0.0421,
|
|
||||||
// },
|
|
||||||
// This region is Bainbridge Island
|
|
||||||
initialRegion: {
|
initialRegion: {
|
||||||
latitude: 47.629536,
|
latitude: 43.653908,
|
||||||
longitude: -122.524162,
|
longitude: -79.384293,
|
||||||
latitudeDelta: 0.0922,
|
latitudeDelta: 0.0922,
|
||||||
longitudeDelta: 0.0421,
|
longitudeDelta: 0.0421,
|
||||||
},
|
},
|
||||||
alwaysShowWorkItemInAR: true,
|
// This region is Bainbridge Island
|
||||||
|
// initialRegion: {
|
||||||
|
// latitude: 47.629536,
|
||||||
|
// longitude: -122.524162,
|
||||||
|
// latitudeDelta: 0.0922,
|
||||||
|
// longitudeDelta: 0.0421,
|
||||||
|
// },
|
||||||
|
// alwaysShowWorkItemInAR: true,
|
||||||
}
|
}
|
||||||
|
|||||||
117
server/src/bin/viewImage.js
Normal file
117
server/src/bin/viewImage.js
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
import parseArgs from "minimist"
|
||||||
|
import chalk from "chalk"
|
||||||
|
import fetch from "node-fetch"
|
||||||
|
import path from "path"
|
||||||
|
import { promisify } from "util"
|
||||||
|
import fs from "fs"
|
||||||
|
import { exec } from "child_process"
|
||||||
|
import autobind from "autobind-decorator"
|
||||||
|
|
||||||
|
const readAsync = promisify(fs.read)
|
||||||
|
const closeAsync = promisify(fs.close)
|
||||||
|
const openAsync = promisify(fs.open)
|
||||||
|
const fstat = promisify(fs.fstat)
|
||||||
|
|
||||||
|
@autobind
|
||||||
|
class ViewImageTool {
|
||||||
|
constructor(toolName, log) {
|
||||||
|
this.toolName = toolName
|
||||||
|
this.log = log
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(argv) {
|
||||||
|
const defaultHostname = "http://localhost:3001"
|
||||||
|
const options = {
|
||||||
|
string: ["user", "password", "hostname", "token"],
|
||||||
|
boolean: ["help", "version"],
|
||||||
|
alias: {
|
||||||
|
u: "user",
|
||||||
|
p: "password",
|
||||||
|
t: "token",
|
||||||
|
h: "hostname",
|
||||||
|
},
|
||||||
|
default: {
|
||||||
|
hostname: defaultHostname,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
let args = parseArgs(argv, options)
|
||||||
|
|
||||||
|
if (args.help) {
|
||||||
|
this.log.info(`
|
||||||
|
usage: ${this.toolName} [options] <id>
|
||||||
|
|
||||||
|
options:
|
||||||
|
-h, --hostname <hostname> Hostname of system. Defaults to ${defaultHostname}
|
||||||
|
-u, --user <email> User email
|
||||||
|
-p, --password <password> User password
|
||||||
|
-t, --token <token> Existing login token
|
||||||
|
`)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args._.length < 1) {
|
||||||
|
this.log.error("Please specify a image asset id")
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
let token = null
|
||||||
|
let assetId = args._[0]
|
||||||
|
const contentTypeJsonHeader = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((args.user && args.password) || args.token) {
|
||||||
|
if (!args.token) {
|
||||||
|
const res = await fetch(args.hostname + "/auth/login", {
|
||||||
|
method: "POST",
|
||||||
|
headers: contentTypeJsonHeader,
|
||||||
|
body: JSON.stringify({
|
||||||
|
email: args.user,
|
||||||
|
password: args.password,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
const obj = await res.json()
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(obj.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.log.info(`Logged in as '${obj.email}'`)
|
||||||
|
token = res.headers.get("Authorization").slice("Bearer ".length)
|
||||||
|
} else {
|
||||||
|
token = args._[0]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.log.error("Specify either user email and password, or token")
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = `${args.hostname}/assets/${assetId}?access_token=${token}`
|
||||||
|
|
||||||
|
this.log.info(url)
|
||||||
|
|
||||||
|
exec("open " + url)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const log = {
|
||||||
|
info: console.error,
|
||||||
|
error: function() {
|
||||||
|
console.error(chalk.red("error:", [...arguments].join(" ")))
|
||||||
|
},
|
||||||
|
warning: function() {
|
||||||
|
console.error(chalk.yellow("warning:", [...arguments].join(" ")))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const tool = new ViewImageTool("viewImage", log)
|
||||||
|
tool
|
||||||
|
.run(process.argv.slice(2))
|
||||||
|
.then((exitCode) => {
|
||||||
|
process.exit(exitCode)
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err)
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user