moves API data to S3, allows external use (#74)

This commit is contained in:
Miguel Sozinho Ramalho
2023-10-09 13:20:37 +01:00
committed by GitHub
parent f8e0b7554a
commit 042346a833
6 changed files with 20 additions and 6 deletions

View File

@@ -3,10 +3,11 @@ const one_day = 1440;
const config = { const config = {
title: "ukraine", title: "ukraine",
display_title: "Civilian Harm\nin Ukraine", display_title: "Civilian Harm\nin Ukraine",
SERVER_ROOT: "https://ukraine.bellingcat.com/ukraine-server", SERVER_ROOT: "https://bellingcat-embeds.ams3.cdn.digitaloceanspaces.com/production/ukr",
EVENTS_EXT: "/api/ukraine/export_events/deeprows", EVENTS_EXT: "/timemap/events.json",
SOURCES_EXT: "/api/ukraine/export_sources/deepids", SOURCES_EXT: "/timemap/sources.json",
ASSOCIATIONS_EXT: "/api/ukraine/export_associations/deeprows", ASSOCIATIONS_EXT: "/timemap/associations.json",
API_DATA: "https://bellingcat-embeds.ams3.cdn.digitaloceanspaces.com/production/ukr/timemap/api.json",
MAPBOX_TOKEN: MAPBOX_TOKEN:
"pk.eyJ1IjoiYmVsbGluZ2NhdC1tYXBib3giLCJhIjoiY2tleW0wbWliMDA1cTJ5bzdkbTRraHgwZSJ9.GJQkjPzj8554VhR5SPsfJg", "pk.eyJ1IjoiYmVsbGluZ2NhdC1tYXBib3giLCJhIjoiY2tleW0wbWliMDA1cTJ5bzdkbTRraHgwZSJ9.GJQkjPzj8554VhR5SPsfJg",
// MEDIA_EXT: "/api/media", // MEDIA_EXT: "/api/media",
@@ -38,7 +39,7 @@ const config = {
{ label: "Zoom to 1 month", duration: 31 * one_day }, { label: "Zoom to 1 month", duration: 31 * one_day },
{ label: "Zoom to 6 months", duration: 6 * 31 * one_day }, { label: "Zoom to 6 months", duration: 6 * 31 * one_day },
{ label: "Zoom to 1 year", duration: 12 * 31 * one_day }, { label: "Zoom to 1 year", duration: 12 * 31 * one_day },
{ label: "Zoom to 1.5 years", duration: 18 * 31 * one_day }, { label: "Zoom to 2 years", duration: 24 * 31 * one_day },
], ],
range: { range: {
/** /**

View File

@@ -10,6 +10,7 @@
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build", "build": "vite build",
"preview": "vite preview",
"dev:wsl": "vite --host", "dev:wsl": "vite --host",
"test": "vitest", "test": "vitest",
"eslint": "eslint src --ext jsx", "eslint": "eslint src --ext jsx",

View File

@@ -214,6 +214,10 @@
"title": "Download events", "title": "Download events",
"description": "Export the most recent available events in different formats.", "description": "Export the most recent available events in different formats.",
"formats": { "formats": {
"api": {
"label": "API",
"description": "An API endpoint where you can always fetch the entire dataset in JSON format with tools like curl. Useful for integrating the data in other services and visualizaitons."
},
"csv": { "csv": {
"label": "CSV", "label": "CSV",
"description": "CSV file where sources and filters are concatenated into a single column each due to data structure limitations." "description": "CSV file where sources and filters are concatenated into a single column each due to data structure limitations."

View File

@@ -3,11 +3,14 @@ import dayjs from "dayjs";
import { Parser } from "@json2csv/plainjs"; import { Parser } from "@json2csv/plainjs";
import copy from "../../common/data/copy.json"; import copy from "../../common/data/copy.json";
import { downloadAsFile } from "../../common/utilities"; import { downloadAsFile } from "../../common/utilities";
import config from "../../../config";
export class DownloadButton extends Component { export class DownloadButton extends Component {
onDownload(format, domain) { onDownload(format, domain) {
let filename = `ukr-civharm-${dayjs().format("YYYY-MM-DD")}`; let filename = `ukr-civharm-${dayjs().format("YYYY-MM-DD")}`;
if (format === "csv") { if (format === "api") {
window.open(config["API_DATA"], '_blank');
}else if (format === "csv") {
let outputData = this.getCsvData(domain); let outputData = this.getCsvData(domain);
downloadAsFile(`${filename}.csv`, outputData); downloadAsFile(`${filename}.csv`, outputData);
} else if (format === "json") { } else if (format === "json") {

View File

@@ -13,6 +13,7 @@ const DownloadPanel = ({ language, title, description, domain }) => {
}} }}
/> />
<hr /> <hr />
<DownloadButton language={language} domain={domain} format="api" />
<DownloadButton language={language} domain={domain} format="csv" /> <DownloadButton language={language} domain={domain} format="csv" />
<DownloadButton language={language} domain={domain} format="json" /> <DownloadButton language={language} domain={domain} format="json" />
</div> </div>

View File

@@ -12,6 +12,10 @@ export default defineConfig({
"/api": { "/api": {
target: "https://ukraine.bellingcat.com/ukraine-server", target: "https://ukraine.bellingcat.com/ukraine-server",
changeOrigin: true, changeOrigin: true,
},
"/timemap": {
target: "https://bellingcat-embeds.ams3.cdn.digitaloceanspaces.com/production/ukr",
changeOrigin: true,
} }
} }
}, },