-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
68 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { Address } from 'ton-core' | ||
|
||
export type PostOffChain = { | ||
url: string | ||
date: Date | ||
author: Address | ||
contentMd: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import type { NftMetadata } from '@d0rich/ton-contracts/wrappers/DSocialNetworkPost' | ||
|
||
export type PostOnChain = NftMetadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './PostOffChain' | ||
export * from './PostOnChain' |
36 changes: 36 additions & 0 deletions
36
apps/d.d0rich.me/src/entities/post/utils/convertPostToOnChain.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { PostOnChain, PostOffChain } from '../model' | ||
import { useAppConfig } from '../../../shared/composables/useAppConfig' | ||
import { etxChar, stxChar } from './symbols' | ||
|
||
const config = useAppConfig() | ||
|
||
export function convertPostToOnChain(model: PostOffChain): PostOnChain { | ||
const name = `Post on D from ${model.date.toLocaleDateString( | ||
'de-DE' | ||
)} by ${model.author.toRawString()}` | ||
const stringBuilder: string[] = [] | ||
stringBuilder.push(`Posted: ${model.date.toLocaleDateString('de-DE')}`) | ||
stringBuilder.push(`Author: ${model.author.toString()}`) | ||
stringBuilder.push(`See on D: ${model.url}`) | ||
stringBuilder.push('') | ||
// TODO: Convert markdown to plain text | ||
stringBuilder.push(model.contentMd) | ||
stringBuilder.push('', '', '') | ||
stringBuilder.push('===== Technical information =====') | ||
stringBuilder.push( | ||
`${stxChar}${JSON.stringify({ | ||
url: model.url, | ||
date: model.date.toISOString(), | ||
author: model.author.toRawString(), | ||
contentMd: model.contentMd | ||
})}${etxChar}` | ||
) | ||
return { | ||
$$type: 'NftMetadata', | ||
image: `https://${ | ||
config.network === 'TESTNET' ? 'testnet.' : '' | ||
}d.d0rich.me/metadata/covers/post.jpg`, | ||
name, | ||
description: stringBuilder.join('\n') | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
apps/d.d0rich.me/src/entities/post/utils/getPostFromOnChain.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Address } from 'ton-core/dist/address/Address' | ||
import type { PostOnChain, PostOffChain } from '../model' | ||
import { etxChar, stxChar } from './symbols' | ||
|
||
export function getPostFromOnChain(metadata: PostOnChain): PostOffChain { | ||
const modelJSON = metadata.description.split(etxChar)[0].split(stxChar)[1] | ||
const model: Record<keyof PostOffChain, string> = JSON.parse(modelJSON) | ||
return { | ||
...model, | ||
date: new Date(model.date), | ||
author: Address.parseRaw(model.author) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** Start of text symbol */ | ||
const stxChar = String.fromCharCode(2) | ||
/** End of text symbol */ | ||
const etxChar = String.fromCharCode(3) | ||
|
||
export { stxChar, etxChar } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.