From 24202106c511eafb036f1eeb6199ac8ec9609479 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 10 Oct 2022 10:42:33 -0400 Subject: [PATCH] showed only the connected wallet's blogs --- scripts/upload.js | 1 - src/components/NavBar.tsx | 49 ++++++---- src/components/NewBlog.tsx | 22 +++-- src/components/Profile.tsx | 13 +-- src/components/SyncWorker.tsx | 87 ++++++++++------- src/slices/dbSlice.ts | 176 +++++++++++++++++++--------------- src/slices/web3Slice.ts | 112 +++------------------- src/utils/config.ts | 2 +- src/utils/rss.ts | 36 ++++--- 9 files changed, 235 insertions(+), 263 deletions(-) diff --git a/scripts/upload.js b/scripts/upload.js index 565b9c2..0a85773 100644 --- a/scripts/upload.js +++ b/scripts/upload.js @@ -67,7 +67,6 @@ api.post('https://api.pinata.cloud/pinning/pinFileToIPFS', data, { 'Content-Type': `multipart/form-data; boundary=${data._boundary}`, }, }).then(res => { - console.log(res.data); }, err => { console.error(err); }); diff --git a/src/components/NavBar.tsx b/src/components/NavBar.tsx index 9e9983a..024aeaa 100644 --- a/src/components/NavBar.tsx +++ b/src/components/NavBar.tsx @@ -2,13 +2,17 @@ import React, { useEffect, useState } from "react"; import { FaEdit, FaHome, FaPlus } from "react-icons/fa"; import { useSelector, useDispatch } from "react-redux"; import { Link } from "react-router-dom"; -import Button from '@mui/material/Button'; -import Menu from '@mui/material/Menu'; -import MenuItem from '@mui/material/MenuItem'; +import Button from "@mui/material/Button"; +import Menu from "@mui/material/Menu"; +import MenuItem from "@mui/material/MenuItem"; import { useNavigate } from "react-router-dom"; -import { disconnectWallet } from 'slices/web3Slice'; -import { AppDispatch } from 'slices/store'; -import { MdOutlineEditLocationAlt, MdOutlineHelpOutline, MdOutlineHome } from "react-icons/md"; +import { disconnectWallet } from "slices/web3Slice"; +import { AppDispatch } from "slices/store"; +import { + MdOutlineEditLocationAlt, + MdOutlineHelpOutline, + MdOutlineHome, +} from "react-icons/md"; import Avatar from "react-avatar"; import { getW3link } from "utils/helper"; @@ -41,7 +45,7 @@ const NavBar = (props: INavBar) => { const handleClick = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; - + const handleClose = () => { setAnchorEl(null); }; @@ -52,24 +56,24 @@ const NavBar = (props: INavBar) => { }; const handleProfile = () => { - navigate('/main/profile'); + navigate("/main/profile"); setAnchorEl(null); }; const handleMyBlogs = () => { - navigate('/main/myblogs'); + navigate("/main/myblogs"); setAnchorEl(null); }; return (
- - Protocol Labs + + Protocol Labs
@@ -93,15 +97,20 @@ const NavBar = (props: INavBar) => { <> { open={open} onClose={handleClose} MenuListProps={{ - 'aria-labelledby': 'basic-button', + "aria-labelledby": "basic-button", }} > Profile diff --git a/src/components/NewBlog.tsx b/src/components/NewBlog.tsx index 9c439f8..69007e4 100644 --- a/src/components/NewBlog.tsx +++ b/src/components/NewBlog.tsx @@ -25,7 +25,7 @@ const NewBlog = (props: INewBlog) => { const [title, setTitle] = useState(""); const [body, setBody] = useState(""); - const {uuid} = useParams(); + const { uuid } = useParams(); const blogs = useSelector((state) => state.db.Blogs); const [curBlog, setCurBlog] = useState(undefined); @@ -46,7 +46,7 @@ const NewBlog = (props: INewBlog) => { NotificationManager.warning("Please input the title", "Warn"); return; } - + if (!removeHtmlTags(body)) { NotificationManager.warning("Please input the text", "Warn"); return; @@ -59,28 +59,30 @@ const NewBlog = (props: INewBlog) => { Title: title, Body: body, Creator: account.toLowerCase(), - BodyCID: '' + BodyCID: "", }; dispatch(createBlog(blog)) .unwrap() .then((blog) => { // handle result here - NotificationManager.success(`"${blog.Title}" ${uuid ? "Updated" : "Created"}`, "Blog Created"); + NotificationManager.success( + `"${blog.Title}" ${uuid ? "Updated" : "Created"}`, + "Blog Created" + ); navigate("/main"); - console.log({ blog }); dispatch(setLoading(false)); }) .catch((rejectedValueOrSerializedError) => { // handle error here - console.log({ rejectedValueOrSerializedError }); + console.error({ rejectedValueOrSerializedError }); dispatch(setLoading(false)); }); }; const onClose = () => { navigate("/main/blogs/" + uuid); - } + }; return (
@@ -99,7 +101,7 @@ const NewBlog = (props: INewBlog) => { value={body} options={{ lineNumbers: true, - mode: 'markdown' + mode: "markdown", }} onBeforeChange={(editor, data, value) => { setBody(value); @@ -112,7 +114,9 @@ const NewBlog = (props: INewBlog) => { {uuid ? "Update" : "Publish"} {uuid && ( - + )}
diff --git a/src/components/Profile.tsx b/src/components/Profile.tsx index bd6a518..cf4a7a0 100644 --- a/src/components/Profile.tsx +++ b/src/components/Profile.tsx @@ -33,7 +33,6 @@ const Profile = (props: IProfile) => { useEffect(() => { setName(currentUser?.Name || ""); setBio(currentUser?.Bio || ""); - console.log({user: currentUser}); setAvatar(null); }, [currentUser]); @@ -50,11 +49,9 @@ const Profile = (props: IProfile) => { let imageUrl: any = null; if (avatar) { imageUrl = await dispatch(uploadImage(avatar)).unwrap(); - console.log({imageUrl}); } else if (currentUser?.Image) { imageUrl = currentUser?.Image; } - const user: IUser = { Type: "ADD_USER", @@ -73,12 +70,11 @@ const Profile = (props: IProfile) => { // handle result here NotificationManager.success("", "Saved"); navigate("/main"); - console.log({ user: user }); dispatch(setLoading(false)); }) .catch((rejectedValueOrSerializedError) => { // handle error here - console.log({ rejectedValueOrSerializedError }); + console.error({ rejectedValueOrSerializedError }); dispatch(setLoading(false)); }); } catch (ex) {} @@ -109,7 +105,12 @@ const Profile = (props: IProfile) => { src={avatar ? URL.createObjectURL(avatar) : ""} /> ) : ( - + )} { const dispatch = useDispatch(); - const isSyncing = useSelector((state) => state.viewState.syncing); + const isSyncing = useSelector( + (state) => state.viewState.syncing + ); + const account = useSelector( + (state) => state.web3.selectedAddress + ); const [progress, setProgress] = useState(0); useEffect(() => { - const lastSyncNumber = getStorageItem(config.LAST_SYNC_NUMBER, 0) || 0; - dispatch(resetFromLocalStorage(lastSyncNumber)); + const lastSyncNumber = + getStorageItem(config.LAST_SYNC_NUMBER + account, 0) || 0; + dispatch(resetFromLocalStorage({ lastSyncNumber, account })); sync(); - }, []); + }, [account]); const sync = async () => { + if (!account) { + return; + } + + console.log({ account }); dispatch(setSyncing(true)); const client = new Web3Storage({ token: config.REACT_APP_WEB3_STORAGE_API_TOKEN, @@ -31,29 +42,26 @@ const SyncWorker = (props: ISyncWorker) => { setProgress(-1); const uploadObjects: Upload[] = []; - console.log({clientList: client.list()}); for await (const upload of client.list()) { uploadObjects.push(upload); } - console.log("getting upload finished"); - uploadObjects.sort((a, b) => (a.created > b.created) ? 1 : -1) - let lastSyncNumber = getStorageItem(config.LAST_SYNC_NUMBER, 0) || 0; + uploadObjects.sort((a, b) => (a.created > b.created ? 1 : -1)); + let lastSyncNumber = getStorageItem(config.LAST_SYNC_NUMBER + account, 0) || 0; const version = getStorageItem(config.VERSION_LABEL, "") || ""; if (version !== config.version) { lastSyncNumber = 0; setStorageItem(config.VERSION_LABEL, config.version); - console.log({lastSyncNumber}); } - - setProgress(lastSyncNumber * 100 / (uploadObjects.length || 1)); + // reads data from the w3.storage + setProgress((lastSyncNumber * 100) / (uploadObjects.length || 1)); for (let i = lastSyncNumber; i < uploadObjects.length; i++) { - console.log({progress}) + setStorageItem(config.LAST_SYNC_NUMBER + account, i); + setProgress((i * 100) / (uploadObjects.length || 1)); + const upload = uploadObjects[i]; if (upload.name.indexOf("image_") === 0) { - setStorageItem(config.LAST_SYNC_NUMBER, i + 1); - setProgress((i + 1) * 100 / (uploadObjects.length || 1)); continue; } @@ -64,50 +72,61 @@ const SyncWorker = (props: ISyncWorker) => { // get IPFS data const contentRes = await api.get(getW3link(upload.cid)); - const {data} = contentRes; + const { data } = contentRes; // parse each transactions - switch (data.Type) { - case "ADD_BLOG": - case "UPDATE_BLOG": { - const contentRes1 = await api.get(getW3link(data.BodyCID)); - data.Body = contentRes1.data; - break; + if (["ADD_BLOG", "UPDATE_BLOG"].includes(String(data.Type))) { + if (data.Creator !== account) { + continue; } - default: - break; + const contentRes1 = await api.get(getW3link(data.BodyCID)); + data.Body = contentRes1.data; + } else if (data.Type === "ADD_USER") { + if (data.Wallet !== account) { + continue; + } } const record = { ...data, CID: upload.cid, - Date: new Date(upload.created) + Date: new Date(upload.created), }; // add record to the local storage - setStorageItem(config.LAST_SYNC_RECORD + i, record); - setStorageItem(config.LAST_SYNC_NUMBER, i + 1); - - setProgress((i + 1) * 100 / (uploadObjects.length || 1)); + setStorageItem(config.LAST_SYNC_RECORD + account + i, record); } - dispatch(resetFromLocalStorage(lastSyncNumber)); + setStorageItem(config.LAST_SYNC_NUMBER + account, uploadObjects.length); + setProgress(100); + + dispatch(resetFromLocalStorage({ lastSyncNumber, account })); dispatch(setSyncing(false)); setProgress(0); - console.log("LastSyncNumber: ", getStorageItem(config.LAST_SYNC_NUMBER, 0)); - const bytes = [8, 1, 18, 64, 156, 104, 197, 108, 98, 238, 128, 116, 13, 126, 208, 222, 80, 194, 183, 170, 167, 73, 250, 124, 95, 102, 184, 215, 105, 153, 34, 130, 205, 105, 151, 223, 0, 176, 176, 185, 153, 101, 20, 176, 194, 194, 102, 62, 44, 89, 48, 122, 163, 78, 28, 242, 74, 14, 169, 203, 130, 18, 135, 200, 126, 8, 192, 182]; + const bytes = [ + 8, 1, 18, 64, 156, 104, 197, 108, 98, 238, 128, 116, 13, 126, 208, 222, + 80, 194, 183, 170, 167, 73, 250, 124, 95, 102, 184, 215, 105, 153, 34, + 130, 205, 105, 151, 223, 0, 176, 176, 185, 153, 101, 20, 176, 194, 194, + 102, 62, 44, 89, 48, 122, 163, 78, 28, 242, 74, 14, 169, 203, 130, 18, + 135, 200, 126, 8, 192, 182, + ]; const name = await Name.from(new Uint8Array(bytes)); const revision = await Name.resolve(name); - console.log("RSS Feed:", revision.value); setTimeout(sync, 60000); }; return isSyncing ? (
- {progress >= 0 && } + {progress >= 0 && ( + + )}
) : null; }; diff --git a/src/slices/dbSlice.ts b/src/slices/dbSlice.ts index 6c8eeb8..3893485 100644 --- a/src/slices/dbSlice.ts +++ b/src/slices/dbSlice.ts @@ -1,98 +1,114 @@ -import { createSlice, createAsyncThunk, PayloadAction } from '@reduxjs/toolkit'; -import { convertTitle, getStorageItem } from 'utils/helper'; -import { Service, Web3Storage } from 'web3.storage'; -import config from 'utils/config'; -import { updateRss } from 'utils/rss'; - -const client = new Web3Storage({ token: config.REACT_APP_WEB3_STORAGE_API_TOKEN } as Service); +import { createSlice, createAsyncThunk, PayloadAction } from "@reduxjs/toolkit"; +import { convertTitle, getStorageItem } from "utils/helper"; +import { Service, Web3Storage } from "web3.storage"; +import config from "utils/config"; +import { updateRss } from "utils/rss"; +const client = new Web3Storage({ + token: config.REACT_APP_WEB3_STORAGE_API_TOKEN, +} as Service); const initialState = { Initialized: false, Blogs: [] as IBlog[], - Users: {} as { [key: string]: IUser; } + Users: {} as { [key: string]: IUser }, } as IDatabase; -export const createBlog = createAsyncThunk('createBlog', async (blog: IBlog, {rejectWithValue}) => { - try { - // upload blog body - let title = "blogbody_" + convertTitle(blog.Title); - let blobBody = new File([blog.Body || ""], title, {type: "text/plain"}) - let cid = await client.put([blobBody], { - name: title, - maxRetries: 3, - wrapWithDirectory: false - }); - blog.BodyCID = cid; - blog.Body = undefined; - - // upload blog - title = "blog_" + convertTitle(blog.Title); - let blob = new File([JSON.stringify(blog, null, 2)], title, {type: "application/json"}) - cid = await client.put([blob], { - name: title, - maxRetries: 3, - wrapWithDirectory: false - }); - blog.CID = cid; - - // update rss - updateRss(); - return blog; - } catch (err: any) { - return rejectWithValue(err.response.data); +export const createBlog = createAsyncThunk( + "createBlog", + async (blog: IBlog, { rejectWithValue }) => { + try { + // upload blog body + let title = "blogbody_" + convertTitle(blog.Title); + let blobBody = new File([blog.Body || ""], title, { type: "text/plain" }); + let cid = await client.put([blobBody], { + name: title, + maxRetries: 3, + wrapWithDirectory: false, + }); + blog.BodyCID = cid; + blog.Body = undefined; + + // upload blog + title = "blog_" + convertTitle(blog.Title); + let blob = new File([JSON.stringify(blog, null, 2)], title, { + type: "application/json", + }); + cid = await client.put([blob], { + name: title, + maxRetries: 3, + wrapWithDirectory: false, + }); + blog.CID = cid; + + // update rss + updateRss(); + return blog; + } catch (err: any) { + return rejectWithValue(err.response.data); + } } -}); - -export const createUser = createAsyncThunk('createUser', async (user: IUser, {rejectWithValue}) => { - try { - const title = "user_" + convertTitle(user.Wallet); - let blob = new File([JSON.stringify(user, null, 2)], title, {type: "application/json"}) - const rootCid = await client.put([blob], { - name: title, - maxRetries: 3, - wrapWithDirectory: false - }); - - user.CID = rootCid; - return user; - } catch (err: any) { - return rejectWithValue(err.response.data); +); + +export const createUser = createAsyncThunk( + "createUser", + async (user: IUser, { rejectWithValue }) => { + try { + const title = "user_" + convertTitle(user.Wallet); + let blob = new File([JSON.stringify(user, null, 2)], title, { + type: "application/json", + }); + const rootCid = await client.put([blob], { + name: title, + maxRetries: 3, + wrapWithDirectory: false, + }); + + user.CID = rootCid; + return user; + } catch (err: any) { + return rejectWithValue(err.response.data); + } } -}); - -export const uploadImage = createAsyncThunk('uploadImage', async (file: File, {rejectWithValue}) => { - try { - const rootCid = await client.put([file], { - name: "image_" + (new Date()).getTime().toString(), - maxRetries: 3, - wrapWithDirectory: false - }); - return rootCid; - } catch (err: any) { - return rejectWithValue(err.response.data); +); + +export const uploadImage = createAsyncThunk( + "uploadImage", + async (file: File, { rejectWithValue }) => { + try { + const rootCid = await client.put([file], { + name: "image_" + new Date().getTime().toString(), + maxRetries: 3, + wrapWithDirectory: false, + }); + return rootCid; + } catch (err: any) { + return rejectWithValue(err.response.data); + } } -}); +); export const dbSlice = createSlice({ - name: 'dbSlice', + name: "dbSlice", // `createSlice` will infer the state type from the `initialState` argument initialState, reducers: { - resetFromLocalStorage: (state: IDatabase, action: PayloadAction) => { + resetFromLocalStorage: (state: IDatabase, action: PayloadAction) => { // dispose individual action - const startNumber = state.Initialized ? action.payload : 0; + const startNumber = state.Initialized ? action.payload.lastSyncNumber : 0; + const account = state.Initialized ? action.payload.account : ""; const blogs = startNumber > 0 ? state.Blogs : []; const users = state.Users; - const lastSyncNumber = getStorageItem(config.LAST_SYNC_NUMBER, 0) || 0; - console.log({lastSyncNumber: lastSyncNumber}); - for (let i = startNumber; i < lastSyncNumber; i++) - { - const data = getStorageItem(config.LAST_SYNC_RECORD + i, {}) || {}; + const lastSyncNumber = + getStorageItem(config.LAST_SYNC_NUMBER + account, 0) || 0; + for (let i = startNumber; i < lastSyncNumber; i++) { + const data = + getStorageItem(config.LAST_SYNC_RECORD + account + i, {}) || {}; if (!data.Date) { continue; } + data.Date = new Date(data.Date); switch (data.Type) { case "ADD_BLOG": @@ -116,18 +132,22 @@ export const dbSlice = createSlice({ } } - blogs.sort((a, b) => (a.Date || new Date()) < (b.Date || new Date()) ? 1 : -1); + blogs.sort((a, b) => + (a.Date || new Date()) < (b.Date || new Date()) ? 1 : -1 + ); state.Blogs = blogs; state.Users = users; state.Initialized = true; - } + }, }, extraReducers: (builder) => { - builder.addCase(createBlog.fulfilled, (state: any, action: PayloadAction) => { - }); + builder.addCase( + createBlog.fulfilled, + (state: any, action: PayloadAction) => {} + ); }, }); -export const {resetFromLocalStorage} = dbSlice.actions; +export const { resetFromLocalStorage } = dbSlice.actions; export default dbSlice.reducer; diff --git a/src/slices/web3Slice.ts b/src/slices/web3Slice.ts index 678c697..c9158d7 100644 --- a/src/slices/web3Slice.ts +++ b/src/slices/web3Slice.ts @@ -1,20 +1,20 @@ -import { createSlice, createAsyncThunk, PayloadAction } from '@reduxjs/toolkit'; -import Web3 from 'web3'; -import Web3Modal from 'web3modal'; -import WalletConnectProvider from '@walletconnect/web3-provider'; +import { createSlice, createAsyncThunk, PayloadAction } from "@reduxjs/toolkit"; +import Web3 from "web3"; +import Web3Modal from "web3modal"; +import WalletConnectProvider from "@walletconnect/web3-provider"; const providerOptions = { walletconnect: { package: WalletConnectProvider, options: { infuraId: process.env.REACT_APP_INFURA_ID, - bridge: 'https://bridge.walletconnect.org/', + bridge: "https://bridge.walletconnect.org/", }, }, }; const web3Modal = new Web3Modal({ - network: 'mainnet', // optional + network: "mainnet", // optional cacheProvider: true, // optional providerOptions, // required }); @@ -27,102 +27,15 @@ const initialState = { chainId: undefined as any, }; -export const connectWallet = createAsyncThunk('connectWallet', async () => { +export const connectWallet = createAsyncThunk("connectWallet", async () => { try { const provider = await web3Modal.connect(); web3 = new Web3(provider); const account = (await web3.eth.getAccounts())?.[0]?.toLowerCase(); const chainId = await web3.eth.net.getId(); - return {web3, account, chainId}; + return { web3, account, chainId }; } catch (ex) { - console.log(ex); - return null; - } -}); - -export const disconnectWallet = createAsyncThunk( - 'disconnectWallet', - async () => { - try { - await web3Modal.clearCachedProvider(); - return null; - } catch { - return null; - } - } -); - -export const web3Slice = createSlice({ - name: 'web3', - // `createSlice` will infer the state type from the `initialState` argument - initialState, - reducers: {}, - extraReducers: (builder) => { - builder.addCase(connectWallet.fulfilled, (state: any, action: PayloadAction) => { - state.web3 = action.payload?.web3; - state.selectedAddress = action.payload?.account; - state.chainId = action.payload?.chainId; - }); - builder.addCase( - disconnectWallet.fulfilled, - (state: any, action: IAction) => { - state.web3 = null; - state.selectedAddress = null; - state.chainId = null; - } - ); - }, -}); - -export default web3Slice.reducer; - - - -/* -import { createSlice, createAsyncThunk, PayloadAction } from "@reduxjs/toolkit"; -import Web3 from "web3"; -import Web3Modal from "web3modal"; -import WalletConnectProvider from "@walletconnect/web3-provider"; -import { enableFilecoinSnap } from "@chainsafe/filsnap-adapter"; -import { initiateFilecoinSnap } from "utils/metamask"; - -const providerOptions = { - walletconnect: { - package: WalletConnectProvider, - options: { - infuraId: process.env.REACT_APP_INFURA_ID, - bridge: "https://bridge.walletconnect.org/", - }, - }, -}; - -const web3Modal = new Web3Modal({ - network: "mainnet", // optional - cacheProvider: false, // optional - providerOptions, // required -}); - -let web3: any; - -const initialState = { - web3: null as any, - metamaskFilecoinSnap: undefined as any, - filecoinApi: undefined as any -}; - -export const connectWallet = createAsyncThunk("connectWallet", async () => { - try { - const installResult = await initiateFilecoinSnap(); - let filecoinApi = null; - if (installResult.isSnapInstalled) { - sessionStorage.setItem("metamask-snap", "connected"); - filecoinApi = await installResult.snap?.getFilecoinSnapApi(); - } - return { - snap: installResult.snap, - filecoinApi - }; - } catch { + console.error(ex); return null; } }); @@ -148,9 +61,9 @@ export const web3Slice = createSlice({ builder.addCase( connectWallet.fulfilled, (state: any, action: PayloadAction) => { - state.metamaskFilecoinSnap = action.payload?.metamaskFilecoinSnap; - state.filecoinApi = action.payload?.filecoinApi; - console.log({ action }); + state.web3 = action.payload?.web3; + state.selectedAddress = action.payload?.account; + state.chainId = action.payload?.chainId; } ); builder.addCase( @@ -165,4 +78,3 @@ export const web3Slice = createSlice({ }); export default web3Slice.reducer; -*/ diff --git a/src/utils/config.ts b/src/utils/config.ts index a54ac56..80a41be 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -4,7 +4,7 @@ const config = { LAST_SYNC_NUMBER: "IPP_LAST_SYNC_NUMBER", LAST_SYNC_RECORD: "LAST_SYNC_RECORD_", VERSION_LABEL: "VERSION", - version: "#6", + version: "#7", RSS_COUNT: 10 }; diff --git a/src/utils/rss.ts b/src/utils/rss.ts index 5f9b234..87d1a2f 100644 --- a/src/utils/rss.ts +++ b/src/utils/rss.ts @@ -1,13 +1,15 @@ import xml from "xml"; -import { Service, Web3Storage } from 'web3.storage'; -import * as Name from 'w3name'; -import config from 'utils/config'; +import { Service, Web3Storage } from "web3.storage"; +import * as Name from "w3name"; +import config from "utils/config"; import { getW3link, removeHtmlTags } from "./helper"; import MarkdownIt from "markdown-it"; import api from "./api"; const md = new MarkdownIt(); -const client = new Web3Storage({ token: config.REACT_APP_WEB3_STORAGE_API_TOKEN } as Service); +const client = new Web3Storage({ + token: config.REACT_APP_WEB3_STORAGE_API_TOKEN, +} as Service); export function generateXmlString(posts: IBlog[]) { const SITE_BASE_URL = "https://ipp-blog.netlify.app/"; @@ -37,7 +39,7 @@ export function generateXmlString(posts: IBlog[]) { { link: SITE_BASE_URL }, { description: "Distributed Blog System" }, { language: "en-us" }, - { lastBuildDate: (new Date()).toString() }, + { lastBuildDate: new Date().toString() }, { generator: "IPP App" }, ...posts.map((post) => { const absoluteHREF = `${SITE_BASE_URL}main/blogs/${post.UUID}`; @@ -47,7 +49,11 @@ export function generateXmlString(posts: IBlog[]) { { pubDate: post.Date?.toString() }, { link: absoluteHREF }, { guid: absoluteHREF }, - { description: { _cdata: removeHtmlTags(md.render(post.Body || "")) } }, + { + description: { + _cdata: removeHtmlTags(md.render(post.Body || "")), + }, + }, /* */ @@ -61,8 +67,6 @@ export function generateXmlString(posts: IBlog[]) { const xmlString = '' + xml(xmlObject); return xmlString; - - } export async function getRecentEvents() { @@ -73,7 +77,7 @@ export async function getRecentEvents() { const blogObjects: IBlog[] = []; for await (const upload of client.list()) { const contentRes = await api.get(getW3link(upload.cid)); - const {data} = contentRes; + const { data } = contentRes; if (data.Type === "ADD_BLOG" || data.Type === "UPDATE_BLOG") { blogObjects.push(data); } @@ -94,24 +98,28 @@ export async function getRecentEvents() { export async function updateRss() { const posts = await getRecentEvents(); - console.log({posts}); const xmlString = generateXmlString(posts); const title = "rss"; - let blob = new File([xmlString], title, {type: "text/xml"}) + let blob = new File([xmlString], title, { type: "text/xml" }); const rootCid = await client.put([blob], { name: title, maxRetries: 3, - wrapWithDirectory: false + wrapWithDirectory: false, }); // name: k51qzi5uqu5dg77idvtml88k2bc6scmi9aftri6nub8f7k73fjbiw8xau3xe46 // path: https://k51qzi5uqu5dg77idvtml88k2bc6scmi9aftri6nub8f7k73fjbiw8xau3xe46.ipns.dweb.link/ // https://k51qzi5uqu5dg77idvtml88k2bc6scmi9aftri6nub8f7k73fjbiw8xau3xe46.ipns.w3s.link/ - const bytes = [8, 1, 18, 64, 156, 104, 197, 108, 98, 238, 128, 116, 13, 126, 208, 222, 80, 194, 183, 170, 167, 73, 250, 124, 95, 102, 184, 215, 105, 153, 34, 130, 205, 105, 151, 223, 0, 176, 176, 185, 153, 101, 20, 176, 194, 194, 102, 62, 44, 89, 48, 122, 163, 78, 28, 242, 74, 14, 169, 203, 130, 18, 135, 200, 126, 8, 192, 182]; + const bytes = [ + 8, 1, 18, 64, 156, 104, 197, 108, 98, 238, 128, 116, 13, 126, 208, 222, 80, + 194, 183, 170, 167, 73, 250, 124, 95, 102, 184, 215, 105, 153, 34, 130, 205, + 105, 151, 223, 0, 176, 176, 185, 153, 101, 20, 176, 194, 194, 102, 62, 44, + 89, 48, 122, 163, 78, 28, 242, 74, 14, 169, 203, 130, 18, 135, 200, 126, 8, + 192, 182, + ]; const name = await Name.from(new Uint8Array(bytes)); const revision = await Name.resolve(name); const nextValue = `/ipfs/${rootCid}`; const nextRevision = await Name.increment(revision, nextValue); await Name.publish(nextRevision, name.key); - console.log("name:", name.toString()); } -- 2.51.2