Skip to content

Commit

Permalink
adapter domain
Browse files Browse the repository at this point in the history
  • Loading branch information
XueMoMo committed Aug 28, 2024
1 parent 91afbc8 commit 0933039
Show file tree
Hide file tree
Showing 16 changed files with 3,863 additions and 1,944 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/docker-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Docker Deploy

on:
workflow_dispatch:

jobs:
deploy:
if: ${{github.ref == 'refs/heads/prod'}}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]

- name: Setup Node v18
uses: actions/setup-node@v1
with:
node-version: v18.19.0

- uses: actions/cache@v3
with:
path: |
.next
.yarn/cache
./node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build
run: yarn export

- name: Build docker and publish
run: |
docker build -t crustio/cloud3-home:latest .
docker login -u ${{ secrets.DOCKER_HUB_USER_NAME }} -p ${{ secrets.DOCKER_HUB_PASSWORD }}
docker push crustio/cloud3-home:latest
- name: Update docker compose
uses: fifsky/ssh-action@master
with:
command: ${{ secrets.RUN_CMD }}
host: ${{ secrets.SSH_HOST }}
user: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:20-alpine as runner

FROM runner
RUN npm install serve -g
WORKDIR /app

COPY /out .

EXPOSE 3000

CMD serve
7 changes: 4 additions & 3 deletions components/common/DragUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import classNames from "classnames";
import CloseBtnSvg from "@public/images/close_btn.svg";
import {ProgressBar} from "@components/common/ProgressBar";
import {openExtUrl} from "@lib/utils";
import {GatewayBase} from "@lib/config";
import {docsUrl, GatewayBase} from "@lib/config";
import React, {useEffect, useRef, useState} from "react";
import axios, {CancelTokenSource} from "axios";
import {upload} from "@lib/files";
import {UploadRes} from "@components/pages/home/SectionTop";
import {useToast} from "@lib/hooks/useToast";
import { DomainRef } from "@lib/hooks/useConfigDomain";

interface IProps{
className?: string,
Expand Down Expand Up @@ -171,12 +172,12 @@ export function DragUpload(p:IProps){
Get download link for this file
</div>
<div className="underline" onClick={()=>openExtUrl(`https://ipfs-scan.io/?cid=${uploadFileInfo.Hash}`)}>Verify on IPFS</div>
<div className="mr-5 w-1/2 underline" onClick={()=>openExtUrl(`https://docs.crustcloud.io`)}>
<div className="mr-5 w-1/2 underline" onClick={()=>openExtUrl(docsUrl())}>
Learn more about Crust Cloud's storage solution
</div>
<div
onClick={() =>
openExtUrl("http://test.crustcloud.io/#/buckets")
openExtUrl(`http://test.${DomainRef.value}/#/buckets`)
}
className="underline"
>
Expand Down
4 changes: 3 additions & 1 deletion components/pages/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { AppLoading } from "@components/common/AppLoading";
import { Toasts } from "@components/common/Toast";
import { useSetDomain } from "@lib/hooks/useConfigDomain";
import { StoreProvider, useInitStore } from "@lib/store/store";
import React from "react";
import { HashRouter, Route, Routes } from "react-router-dom";
import ReactTooltip from "react-tooltip";
import Home from "./home/Home";
import { Admin } from "./main/Admin";
import { Bucket } from "./main/Bucket";
import { Buckets } from "./main/Buckets";
import { Mint } from "./main/Mint";
import { Setting } from "./main/Setting";
import { Providers } from "./Providers";
import { Admin } from "./main/Admin";

function WrapStoreProvider({ children }: { children: React.ReactNode }) {
const store = useInitStore();
Expand All @@ -19,6 +20,7 @@ function WrapStoreProvider({ children }: { children: React.ReactNode }) {

export default React.memo(() => {
console.info("Root:", new Date().getTime());
useSetDomain();
return (
<Providers>
<WrapStoreProvider>
Expand Down
4 changes: 3 additions & 1 deletion components/pages/home/SectionTop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {openExtUrl } from "@lib/utils";
import React, {useState} from "react";
import {useOnce} from "@react-spring/shared";
import { IconCloud3 } from "@components/common/icons";
import { DomainRef } from "@lib/hooks/useConfigDomain";
import { docsUrl } from "@lib/config";

export interface UploadRes {
Hash: string;
Expand Down Expand Up @@ -40,7 +42,7 @@ export const SectionTop = React.memo(() => {
<Button
text="Documentations"
className="btn-173 border-white text-white"
onClick={()=>openExtUrl('https://docs.crustcloud.io/')}
onClick={()=>openExtUrl(docsUrl())}
/>
<Button
text="Launch App"
Expand Down
4 changes: 3 additions & 1 deletion components/pages/home/component/PublisherCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {Modal} from "@components/modals/Modal";
import {CommonModalClose} from "@components/pages/home/component/CommonModalClose";
import React from "react";
import {BucketCode} from "@components/common/BucketCode";
import { DomainRef } from "@lib/hooks/useConfigDomain";
import { docsUrl } from "@lib/config";

interface IProps{
onClose: any
Expand Down Expand Up @@ -39,7 +41,7 @@ import { MdEditor } from '@cloud3/vue-widgets'
<Modal className="p-0">
<div className="bg-white min-w-[56rem] flex flex-col relative p-6">
<div className="flex justify-between items-center mb-6">
<a className="text-2xl underline text-black-1" href="https://docs.crustcloud.io" target="_blank">Dev Guidance</a>
<a className="text-2xl underline text-black-1" href={docsUrl()} target="_blank">Dev Guidance</a>
<CommonModalClose className="mt-[-0.3rem]" onClose={()=>onClose && onClose()} />
</div>
<div>
Expand Down
3 changes: 2 additions & 1 deletion components/pages/home/component/StorageCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Modal} from "@components/modals/Modal";
import {CommonModalClose} from "@components/pages/home/component/CommonModalClose";
import React from "react";
import {BucketCode} from "@components/common/BucketCode";
import { docsUrl } from "@lib/config";

interface IProps{
onClose: any
Expand Down Expand Up @@ -38,7 +39,7 @@ import { DragStorage } from '@cloud3/vue-widgets'
<Modal className="p-0">
<div className="bg-white min-w-[56rem] flex flex-col relative p-6">
<div className="flex justify-between items-center mb-6">
<a className="text-2xl underline text-black-1" href="https://docs.crustcloud.io" target="_blank">Dev Guidance</a>
<a className="text-2xl underline text-black-1" href={docsUrl()} target="_blank">Dev Guidance</a>
<CommonModalClose className="mt-[-0.3rem]" onClose={()=>onClose && onClose()} />
</div>
<div>
Expand Down
6 changes: 3 additions & 3 deletions components/pages/main/Bucket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { useOnce } from "@react-spring/shared";
import { genUrl, pinUrl } from "@lib/http";
import { useToast } from "@lib/hooks/useToast";
import { useAccount } from "wagmi";
import { GatewayBaseBucket } from "@lib/config";
import { docsUrl, GatewayBaseBucket } from "@lib/config";
import algoWallet from "@lib/algorand/algoWallet";
import algodClient from "@lib/algorand/algodClient";

Expand Down Expand Up @@ -62,10 +62,10 @@ curl -X POST '${pinUrl("/psa/pins")}' \
<BucketCode code={code} />
<div className=" mt-8 text-xl font-medium">Get more references</div>
<div className=" mt-4 flex flex-wrap">
<a className=" underline text-black-1 mr-5" target="_blank" href="https://docs.crustcloud.io/w3bucket/aboutnft">
<a className=" underline text-black-1 mr-5" target="_blank" href={`${docsUrl()}/w3bucket/aboutnft`}>
General Guidance on W3Bucket
</a>
<a className=" underline text-black-1 mr-5" target="_blank" href="https://docs.crustcloud.io/w3bucket/uploadfile">
<a className=" underline text-black-1 mr-5" target="_blank" href={`${docsUrl()}/w3bucket/uploadfile`}>
Using APIs and W3Auth
</a>
</div>
Expand Down
4 changes: 2 additions & 2 deletions components/pages/main/MainLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Logo } from "@components/common/Logo";
import { IconSetting } from "@components/common/icons";
import { ConnectWallet } from "@components/modals/ConnectWallet";
import algoWallet from "@lib/algorand/algoWallet";
import { ChainIcon, SupportChain } from "@lib/config";
import { ChainIcon, docsUrl, SupportChain } from "@lib/config";
import { IS_DEV, IS_TEST } from "@lib/env";
import { useOn } from "@lib/hooks/tools";
import { useConnected } from "@lib/hooks/useConnected";
Expand Down Expand Up @@ -60,7 +60,7 @@ export const MainLayout = React.memo((p: { menuId: number; tit?: React.ReactNode
id: 3,
icon: "cru-fo-homework",
text: "Docs",
url: "https://docs.crustcloud.io",
url: docsUrl(),
},
];
if (showAdmin) {
Expand Down
10 changes: 6 additions & 4 deletions lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IS_TEST } from "@lib/env";
import * as chain from "wagmi/chains";
import { IS_DEV } from "./env";
import { DomainRef } from "./hooks/useConfigDomain";

export const GA_ID = IS_DEV ? "-" : "-";
export let W3Bucket_Adress: `0x${string}` = "0x";
Expand Down Expand Up @@ -50,11 +51,11 @@ export interface AuthIpfsEndpoint {
value: string;
}

export const GatewayList: AuthIpfsEndpoint[] = [
export const GatewayList = (): AuthIpfsEndpoint[] => [
{
location: "Seattle, US",
name: "Thunder Gateway",
value: "https://gw-seattle.crustcloud.io",
value: `https://gw-seattle.${DomainRef.value}`,
},
];
// 'https://ipfs-gw.decloud.foundation'
Expand All @@ -64,10 +65,11 @@ export const GatewayBase = "https://cf-ipfs.com";
// for BucketGatewayBase
export const GatewayBaseBucket = "https://ipfsgw.live";


export const ChainIcon = {
[chain.mainnet.id]: "/images/chain/ethereum.png",
[chain.arbitrum.id]: "/images/chain/arbitrum.png",
[chain.base.id]: "/images/chain/base.png",
[chain.optimism.id]: "/images/chain/optimism.png",
}
};

export const docsUrl = () => `https://docs.${DomainRef.value}`;
9 changes: 5 additions & 4 deletions lib/hooks/useBuckets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import { W3BucketMetadata } from "@lib/type";
import { sumBy } from "lodash";
import algoWallet from "@lib/algorand/algoWallet";
import algodClient from "@lib/algorand/algodClient";
import { DomainRef } from "./useConfigDomain";

export async function getFileHistory(ipns: string) {
try {
const cid = (
await axios.get<{ Path: string }>(
`${GatewayList[0].value}/api/v0/name/resolve?arg=${ipns}`
`${GatewayList()[0].value}/api/v0/name/resolve?arg=${ipns}`
)
).data;
const fileList = (
await axios.get<any[]>(`https://gw-seattle.crustcloud.io${cid.Path}`)
await axios.get<any[]>(`https://gw-seattle.${DomainRef.value}${cid.Path}`)
).data;
return fileList;
} catch (error) {
Expand All @@ -43,7 +44,7 @@ export function useBuckets() {
const tokenUri = await w3b.tokenURI(tokenId);
const metadata = (
await axios.get<W3BucketMetadata>(
tokenUri.replace("ipfs://", `${GatewayList[0].value}/ipfs/`)
tokenUri.replace("ipfs://", `${GatewayList()[0].value}/ipfs/`)
)
).data;
const ipns = metadata.file_history.replace("ipns://", "");
Expand Down Expand Up @@ -91,7 +92,7 @@ export async function getAlgoBuckets() {
const tokenUri = tokenInfo['params']['url'];
const metadata = (
await axios.get<W3BucketMetadata>(
tokenUri.replace("ipfs://", `${GatewayList[0].value}/ipfs/`)
tokenUri.replace("ipfs://", `${GatewayList()[0].value}/ipfs/`)
)
).data;
const ipns = metadata.file_history.replace("ipns://", "");
Expand Down
32 changes: 32 additions & 0 deletions lib/hooks/useConfigDomain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useEffect, useMemo } from "react";

export const DomainRef = {
value: "crustcloud.io",
};

const supportDomain = ["crustcloud.io", "crustcloud.app"];

export const getAvilableDomain = () => {
if (location.hostname == "localhost") return supportDomain[0];
if (location.hostname.match(/^\d+\.\d+\.\d+\.\d+$/)?.length == 1) return supportDomain[0];
const domains = location.hostname.split(".");
let domain = domains.slice(-2).join(".");
if (domains[1] == "ipns") {
domain = domains[0].replaceAll("-", ".");
}
if (supportDomain.includes(domain)) {
return domain;
}
return supportDomain[0];
};
export function useConfigDomain() {
useEffect(() => {
DomainRef.value = getAvilableDomain();
}, []);
}

export function useSetDomain() {
useMemo(() => {
DomainRef.value = getAvilableDomain();
}, []);
}
6 changes: 3 additions & 3 deletions lib/hooks/useGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export interface UseGateway {

function getCurrent() {
const lastValue = localStorage.getItem("last_gateway");
const last = GatewayList.find((item) => item.value === lastValue);
const last = GatewayList().find((item) => item.value === lastValue);
console.info("last-:", last);
if (last) return last;
return GatewayList[0];
return GatewayList()[0];
}
export function useGateway(): UseGateway {
const {
Expand All @@ -29,5 +29,5 @@ export function useGateway(): UseGateway {
oUpdate({ currentGateway: item });
localStorage.setItem('last_gateway', item.value)
});
return { list: GatewayList, setCurrent, current };
return { list: GatewayList(), setCurrent, current };
}
15 changes: 8 additions & 7 deletions lib/http.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { AxiosResponse } from "axios";
import { IS_DEV, IS_TEST } from "./env";
import { W3BucketMetadata } from "./type";
import { DomainRef } from "./hooks/useConfigDomain";

export function genUrl(path: `/${string}`) {
let base = "https://api.crustcloud.io";
if (IS_DEV) base = "https://beta-api.crustcloud.io";
if (IS_TEST) base = "https://test-api.crustcloud.io";
let base = `https://api.${DomainRef.value}`;
if (IS_DEV) base = `https://beta-api.${DomainRef.value}`;
if (IS_TEST) base = `https://test-api.${DomainRef.value}`;
return `${base}${path}`;
}

export function pinUrl(path: `/${string}`){
let base = "https://pin.crustcloud.io";
if (IS_DEV) base = "https://beta-pin.crustcloud.io";
if (IS_TEST) base = "https://test-pin.crustcloud.io";
export function pinUrl(path: `/${string}`) {
let base = `https://pin.${DomainRef.value}`;
if (IS_DEV) base = `https://beta-pin.${DomainRef.value}`;
if (IS_TEST) base = `https://test-pin.${DomainRef.value}`;
return `${base}${path}`;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export function ipfsUrl(cid: string) {
return `${GatewayBase}/ipfs/${cid}`;
}
export function ipnsUrl(ipns: string) {
return `${GatewayList[0].value}/ipns/${ipns}`;
return `${GatewayList()[0].value}/ipns/${ipns}`;
}
export function randomNum(Min, Max) {
let Range = Max - Min;
Expand Down
Loading

0 comments on commit 0933039

Please sign in to comment.