add paywall to price export
This commit is contained in:
parent
a0c8a3900a
commit
402367e98d
@ -10,11 +10,9 @@
|
|||||||
swapComponent,
|
swapComponent,
|
||||||
governmentContractComponent,
|
governmentContractComponent,
|
||||||
optionsNetFlowComponent,
|
optionsNetFlowComponent,
|
||||||
borrowedShareComponent,
|
|
||||||
clinicalTrialComponent,
|
clinicalTrialComponent,
|
||||||
optionComponent,
|
optionComponent,
|
||||||
failToDeliverComponent,
|
failToDeliverComponent,
|
||||||
marketMakerComponent,
|
|
||||||
screenWidth,
|
screenWidth,
|
||||||
displayCompanyName,
|
displayCompanyName,
|
||||||
numberOfUnreadNotification,
|
numberOfUnreadNotification,
|
||||||
@ -46,8 +44,7 @@
|
|||||||
import { convertTimestamp } from "$lib/utils";
|
import { convertTimestamp } from "$lib/utils";
|
||||||
import { Button } from "$lib/components/shadcn/button/index.js";
|
import { Button } from "$lib/components/shadcn/button/index.js";
|
||||||
import * as DropdownMenu from "$lib/components/shadcn/dropdown-menu/index.js";
|
import * as DropdownMenu from "$lib/components/shadcn/dropdown-menu/index.js";
|
||||||
|
import { goto } from "$app/navigation";
|
||||||
import toast from "svelte-french-toast";
|
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
export let form;
|
export let form;
|
||||||
@ -708,49 +705,52 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function exportData(timePeriod: string) {
|
async function exportData(timePeriod: string) {
|
||||||
let exportList = [];
|
if (data?.user?.tier === "Pro") {
|
||||||
|
let exportList = [];
|
||||||
|
|
||||||
const response = await fetch("/api/export-price-data", {
|
const response = await fetch("/api/export-price-data", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ ticker: $stockTicker, timePeriod: timePeriod }),
|
body: JSON.stringify({ ticker: $stockTicker, timePeriod: timePeriod }),
|
||||||
});
|
});
|
||||||
|
|
||||||
exportList = await response.json();
|
exportList = await response.json();
|
||||||
|
|
||||||
exportList = exportList?.map(({ time, open, high, low, close, date }) => ({
|
exportList = exportList?.map(
|
||||||
date: timePeriod === "max" ? time : date, // Use 'time' if timePeriod is "max", otherwise use 'date'
|
({ time, open, high, low, close, date }) => ({
|
||||||
open,
|
date: timePeriod === "max" ? time : date, // Use 'time' if timePeriod is "max", otherwise use 'date'
|
||||||
high,
|
open,
|
||||||
low,
|
high,
|
||||||
close,
|
low,
|
||||||
}));
|
close,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
const csvRows = [];
|
const csvRows = [];
|
||||||
|
|
||||||
// Add headers row
|
// Add headers row
|
||||||
csvRows.push("time,open,high,low,close");
|
csvRows.push("time,open,high,low,close");
|
||||||
|
|
||||||
// Add data rows
|
// Add data rows
|
||||||
for (const row of exportList) {
|
for (const row of exportList) {
|
||||||
const csvRow = `${row.date},${row.open},${row.high},${row.low},${row.close}`;
|
const csvRow = `${row.date},${row.open},${row.high},${row.low},${row.close}`;
|
||||||
csvRows.push(csvRow);
|
csvRows.push(csvRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create CSV blob and trigger download
|
// Create CSV blob and trigger download
|
||||||
const csv = csvRows.join("\n");
|
const csv = csvRows.join("\n");
|
||||||
const blob = new Blob([csv], { type: "text/csv" });
|
const blob = new Blob([csv], { type: "text/csv" });
|
||||||
const url = window.URL.createObjectURL(blob);
|
const url = window.URL.createObjectURL(blob);
|
||||||
const a = document.createElement("a");
|
const a = document.createElement("a");
|
||||||
a.setAttribute("hidden", "");
|
a.setAttribute("hidden", "");
|
||||||
a.setAttribute("href", url);
|
a.setAttribute("href", url);
|
||||||
a.setAttribute("download", `${$stockTicker}_${timePeriod}.csv`);
|
a.setAttribute("download", `${$stockTicker}_${timePeriod}.csv`);
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
/*
|
/*
|
||||||
if (data?.user) {
|
if (data?.user) {
|
||||||
const response = await fetch("/api/historical-price", {
|
const response = await fetch("/api/historical-price", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@ -800,6 +800,9 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
} else {
|
||||||
|
goto("/pricing");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateClosePrice(data, extendPriceChart) {
|
function updateClosePrice(data, extendPriceChart) {
|
||||||
@ -1189,37 +1192,35 @@
|
|||||||
on:click={() => exportData("30min")}
|
on:click={() => exportData("30min")}
|
||||||
class="cursor-pointer hover:bg-[#27272A]"
|
class="cursor-pointer hover:bg-[#27272A]"
|
||||||
>
|
>
|
||||||
<!--<svg
|
<svg
|
||||||
class="w-3.5 h-3.5 mr-1 {data?.user?.tier === 'Pro'
|
class="w-3.5 h-3.5 mr-1 {data?.user?.tier === 'Pro'
|
||||||
? 'hidden'
|
? 'hidden'
|
||||||
: ''}"
|
: ''}"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
viewBox="0 0 24 24"
|
viewBox="0 0 24 24"
|
||||||
><path
|
><path
|
||||||
fill="#A3A3A3"
|
fill="#A3A3A3"
|
||||||
d="M17 9V7c0-2.8-2.2-5-5-5S7 4.2 7 7v2c-1.7 0-3 1.3-3 3v7c0 1.7 1.3 3 3 3h10c1.7 0 3-1.3 3-3v-7c0-1.7-1.3-3-3-3M9 7c0-1.7 1.3-3 3-3s3 1.3 3 3v2H9z"
|
d="M17 9V7c0-2.8-2.2-5-5-5S7 4.2 7 7v2c-1.7 0-3 1.3-3 3v7c0 1.7 1.3 3 3 3h10c1.7 0 3-1.3 3-3v-7c0-1.7-1.3-3-3-3M9 7c0-1.7 1.3-3 3-3s3 1.3 3 3v2H9z"
|
||||||
/></svg
|
/></svg
|
||||||
>
|
>
|
||||||
-->
|
|
||||||
30 min
|
30 min
|
||||||
</DropdownMenu.Item>
|
</DropdownMenu.Item>
|
||||||
<DropdownMenu.Item
|
<DropdownMenu.Item
|
||||||
on:click={() => exportData("1hour")}
|
on:click={() => exportData("1hour")}
|
||||||
class="cursor-pointer hover:bg-[#27272A]"
|
class="cursor-pointer hover:bg-[#27272A]"
|
||||||
>
|
>
|
||||||
<!--
|
<svg
|
||||||
<svg
|
class="w-3.5 h-3.5 mr-1 {data?.user?.tier === 'Pro'
|
||||||
class="w-3.5 h-3.5 mr-1 {data?.user?.tier === 'Pro'
|
? 'hidden'
|
||||||
? 'hidden'
|
: ''}"
|
||||||
: ''}"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
viewBox="0 0 24 24"
|
||||||
viewBox="0 0 24 24"
|
><path
|
||||||
><path
|
fill="#A3A3A3"
|
||||||
fill="#A3A3A3"
|
d="M17 9V7c0-2.8-2.2-5-5-5S7 4.2 7 7v2c-1.7 0-3 1.3-3 3v7c0 1.7 1.3 3 3 3h10c1.7 0 3-1.3 3-3v-7c0-1.7-1.3-3-3-3M9 7c0-1.7 1.3-3 3-3s3 1.3 3 3v2H9z"
|
||||||
d="M17 9V7c0-2.8-2.2-5-5-5S7 4.2 7 7v2c-1.7 0-3 1.3-3 3v7c0 1.7 1.3 3 3 3h10c1.7 0 3-1.3 3-3v-7c0-1.7-1.3-3-3-3M9 7c0-1.7 1.3-3 3-3s3 1.3 3 3v2H9z"
|
/></svg
|
||||||
/></svg
|
>
|
||||||
>
|
|
||||||
-->
|
|
||||||
1 hour
|
1 hour
|
||||||
</DropdownMenu.Item>
|
</DropdownMenu.Item>
|
||||||
<DropdownMenu.Item
|
<DropdownMenu.Item
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user