Skip to content

Commit

Permalink
moves API data to S3, allows external use (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
msramalho authored Oct 9, 2023
1 parent f8e0b75 commit 042346a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
11 changes: 6 additions & 5 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ const one_day = 1440;
const config = {
title: "ukraine",
display_title: "Civilian Harm\nin Ukraine",
SERVER_ROOT: "https://ukraine.bellingcat.com/ukraine-server",
EVENTS_EXT: "/api/ukraine/export_events/deeprows",
SOURCES_EXT: "/api/ukraine/export_sources/deepids",
ASSOCIATIONS_EXT: "/api/ukraine/export_associations/deeprows",
SERVER_ROOT: "https://bellingcat-embeds.ams3.cdn.digitaloceanspaces.com/production/ukr",
EVENTS_EXT: "/timemap/events.json",
SOURCES_EXT: "/timemap/sources.json",
ASSOCIATIONS_EXT: "/timemap/associations.json",
API_DATA: "https://bellingcat-embeds.ams3.cdn.digitaloceanspaces.com/production/ukr/timemap/api.json",
MAPBOX_TOKEN:
"pk.eyJ1IjoiYmVsbGluZ2NhdC1tYXBib3giLCJhIjoiY2tleW0wbWliMDA1cTJ5bzdkbTRraHgwZSJ9.GJQkjPzj8554VhR5SPsfJg",
// MEDIA_EXT: "/api/media",
Expand Down Expand Up @@ -38,7 +39,7 @@ const config = {
{ label: "Zoom to 1 month", duration: 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.5 years", duration: 18 * 31 * one_day },
{ label: "Zoom to 2 years", duration: 24 * 31 * one_day },
],
range: {
/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"dev:wsl": "vite --host",
"test": "vitest",
"eslint": "eslint src --ext jsx",
Expand Down
4 changes: 4 additions & 0 deletions src/common/data/copy.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@
"title": "Download events",
"description": "Export the most recent available events in different 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": {
"label": "CSV",
"description": "CSV file where sources and filters are concatenated into a single column each due to data structure limitations."
Expand Down
5 changes: 4 additions & 1 deletion src/components/controls/DownloadButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import dayjs from "dayjs";
import { Parser } from "@json2csv/plainjs";
import copy from "../../common/data/copy.json";
import { downloadAsFile } from "../../common/utilities";
import config from "../../../config";

export class DownloadButton extends Component {
onDownload(format, domain) {
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);
downloadAsFile(`${filename}.csv`, outputData);
} else if (format === "json") {
Expand Down
1 change: 1 addition & 0 deletions src/components/controls/DownloadPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const DownloadPanel = ({ language, title, description, domain }) => {
}}
/>
<hr />
<DownloadButton language={language} domain={domain} format="api" />
<DownloadButton language={language} domain={domain} format="csv" />
<DownloadButton language={language} domain={domain} format="json" />
</div>
Expand Down
4 changes: 4 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export default defineConfig({
"/api": {
target: "https://ukraine.bellingcat.com/ukraine-server",
changeOrigin: true,
},
"/timemap": {
target: "https://bellingcat-embeds.ams3.cdn.digitaloceanspaces.com/production/ukr",
changeOrigin: true,
}
}
},
Expand Down

0 comments on commit 042346a

Please sign in to comment.