forked from MapComplete/MapComplete
Fix: maproulette endpoints
This commit is contained in:
parent
e37f90855f
commit
bbf6d62c86
2 changed files with 49 additions and 44 deletions
|
@ -1,14 +1,17 @@
|
||||||
import Constants from "../Models/Constants"
|
import Constants from "../Models/Constants";
|
||||||
|
|
||||||
export default class Maproulette {
|
export default class Maproulette {
|
||||||
public static readonly STATUS_OPEN = 0
|
|
||||||
public static readonly STATUS_FIXED = 1
|
public static readonly defaultEndpoint = "https://maproulette.org/api/v2";
|
||||||
public static readonly STATUS_FALSE_POSITIVE = 2
|
|
||||||
public static readonly STATUS_SKIPPED = 3
|
public static readonly STATUS_OPEN = 0;
|
||||||
public static readonly STATUS_DELETED = 4
|
public static readonly STATUS_FIXED = 1;
|
||||||
public static readonly STATUS_ALREADY_FIXED = 5
|
public static readonly STATUS_FALSE_POSITIVE = 2;
|
||||||
public static readonly STATUS_TOO_HARD = 6
|
public static readonly STATUS_SKIPPED = 3;
|
||||||
public static readonly STATUS_DISABLED = 9
|
public static readonly STATUS_DELETED = 4;
|
||||||
|
public static readonly STATUS_ALREADY_FIXED = 5;
|
||||||
|
public static readonly STATUS_TOO_HARD = 6;
|
||||||
|
public static readonly STATUS_DISABLED = 9;
|
||||||
|
|
||||||
public static readonly STATUS_MEANING = {
|
public static readonly STATUS_MEANING = {
|
||||||
0: "Open",
|
0: "Open",
|
||||||
|
@ -18,28 +21,47 @@ export default class Maproulette {
|
||||||
4: "Deleted",
|
4: "Deleted",
|
||||||
5: "Already fixed",
|
5: "Already fixed",
|
||||||
6: "Too hard",
|
6: "Too hard",
|
||||||
9: "Disabled",
|
9: "Disabled"
|
||||||
}
|
};
|
||||||
|
public static singleton = new Maproulette();
|
||||||
/*
|
/*
|
||||||
* The API endpoint to use
|
* The API endpoint to use
|
||||||
*/
|
*/
|
||||||
endpoint: string
|
endpoint: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The API key to use for all requests
|
* The API key to use for all requests
|
||||||
*/
|
*/
|
||||||
private readonly apiKey: string
|
private readonly apiKey: string;
|
||||||
|
|
||||||
public static singleton = new Maproulette()
|
|
||||||
public static readonly defaultEndpoint = "https://maproulette.org/api/v2"
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Maproulette instance
|
* Creates a new Maproulette instance
|
||||||
* @param endpoint The API endpoint to use
|
* @param endpoint The API endpoint to use
|
||||||
*/
|
*/
|
||||||
constructor(endpoint: string = Maproulette.defaultEndpoint) {
|
constructor(endpoint?: string) {
|
||||||
this.endpoint = endpoint
|
this.endpoint = endpoint ?? Maproulette.defaultEndpoint;
|
||||||
this.apiKey = Constants.MaprouletteApiKey
|
if(!this.endpoint ){
|
||||||
|
throw "MapRoulette endpoint is undefined. Make sure that `Maproulette.defaultEndpoint` is defined on top of the class"
|
||||||
|
}
|
||||||
|
this.apiKey = Constants.MaprouletteApiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a status text into the corresponding number
|
||||||
|
*
|
||||||
|
* Maproulette.codeToIndex("Created") // => 0
|
||||||
|
* Maproulette.codeToIndex("qdsf") // => undefined
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static codeToIndex(code: string): number | undefined {
|
||||||
|
if (code === "Created") {
|
||||||
|
return Maproulette.STATUS_OPEN;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < 9; i++) {
|
||||||
|
if (Maproulette.STATUS_MEANING["" + i] === code) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,36 +82,18 @@ export default class Maproulette {
|
||||||
completionResponses?: Record<string, string>
|
completionResponses?: Record<string, string>
|
||||||
}
|
}
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
console.log("Maproulette: setting", `${this.endpoint}/task/${taskId}/${status}`, options);
|
||||||
const response = await fetch(`${this.endpoint}/task/${taskId}/${status}`, {
|
const response = await fetch(`${this.endpoint}/task/${taskId}/${status}`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
apiKey: this.apiKey,
|
apiKey: this.apiKey
|
||||||
},
|
},
|
||||||
body: options !== undefined ? JSON.stringify(options) : undefined,
|
body: options !== undefined ? JSON.stringify(options) : undefined
|
||||||
})
|
});
|
||||||
if (response.status !== 204) {
|
if (response.status !== 204) {
|
||||||
console.log(`Failed to close task: ${response.status}`)
|
console.log(`Failed to close task: ${response.status}`);
|
||||||
throw `Failed to close task: ${response.status}`
|
throw `Failed to close task: ${response.status}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a status text into the corresponding number
|
|
||||||
*
|
|
||||||
* Maproulette.codeToIndex("Created") // => 0
|
|
||||||
* Maproulette.codeToIndex("qdsf") // => undefined
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static codeToIndex(code: string): number | undefined {
|
|
||||||
if (code === "Created") {
|
|
||||||
return Maproulette.STATUS_OPEN
|
|
||||||
}
|
|
||||||
for (let i = 0; i < 9; i++) {
|
|
||||||
if (Maproulette.STATUS_MEANING["" + i] === code) {
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,6 +111,7 @@ export default class TagApplyButton implements AutoAction, SpecialVisualization
|
||||||
|
|
||||||
while (spec.length > 0) {
|
while (spec.length > 0) {
|
||||||
const [part] = spec.match(/((\\;)|[^;])*/)
|
const [part] = spec.match(/((\\;)|[^;])*/)
|
||||||
|
console.log(("Spec is"), part, spec)
|
||||||
spec = spec.substring(part.length + 1) // +1 to remove the pending ';' as well
|
spec = spec.substring(part.length + 1) // +1 to remove the pending ';' as well
|
||||||
const kv = part.split("=").map((s) => s.trim().replace("\\;", ";"))
|
const kv = part.split("=").map((s) => s.trim().replace("\\;", ";"))
|
||||||
if (kv.length == 2) {
|
if (kv.length == 2) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue