Skip to content

Commit

Permalink
Merge branch 'master' into feat/update-resource-discussion-types
Browse files Browse the repository at this point in the history
  • Loading branch information
mckrava committed Oct 11, 2023
2 parents ebdc034 + 555e3c9 commit 5e5546b
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## 0.8.14 - 2023-05-31
### Added
- update `pinContent` method: add property 'asLink' that allow use ipfsCluster for pinning `@subsocial/utils`
- remove `memoize` for createPostSlug fn

## 0.8.13 - 2023-05-31
### Added
- add nacl realisation for asymmetric encryption to `@subsocial/utils`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
"ts-jest": "^26.5.1",
"typescript": "4.6.x"
},
"version": "0.8.13"
"version": "0.8.15-beta.0"
}
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@subsocial/api",
"version": "0.8.13",
"version": "0.8.15-beta.0",
"description": "JavaScript API for Subsocial blockchain.",
"author": "DappForce contributors",
"license": "GPL-3.0-only",
Expand Down
22 changes: 13 additions & 9 deletions packages/api/src/ipfs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ export class SubsocialIpfsApi {
})
content[cidStr] = res.value
} else {
const res = await axios.get(
`${this._ipfsNodeUrl}/ipfs/${cid.toV1()}?timeout=${timeout}`
)
const data = res.data
const res = await this.client.cat(cid, { timeout })

if (typeof data === 'object') {
content[cidStr] = data
let data = ''
for await (const chunk of res) {
data += chunk.toString()
}

content[cidStr] = JSON.parse(data)
}
} catch (err) {
log.error(`Failed to load cid ${cid.toString()}:`, err)
Expand All @@ -211,13 +211,17 @@ export class SubsocialIpfsApi {
}

/** Pin content in IPFS */
async pinContent(cid: IpfsCid, properties?: Record<any, any>) {
async pinContent(cid: IpfsCid, props?: Record<'asLink' | string, any>) {
const url = props?.asLink
? `${this._ipfsClusterUrl}/pins/${cid.toString()}`
: `${this._ipfsClusterUrl}/pins/`

const data = {
cid: cid.toString(),
...properties
...props
}

const res = await axios.post(this._ipfsClusterUrl + '/pins/', data, {
const res = await axios.post(url, data, {
headers: this.pinHeaders
})

Expand Down
2 changes: 1 addition & 1 deletion packages/definitions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@subsocial/definitions",
"version": "0.8.13",
"version": "0.8.15-beta.0",
"description": "Subsocial definitions using @polkadot/typegen to generate type definitions",
"main": "index.js",
"repository": "https://github.com/dappforce/subsocial-js/packages/definitions",
Expand Down
2 changes: 1 addition & 1 deletion packages/elasticsearch/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@subsocial/elasticsearch",
"version": "0.8.13",
"version": "0.8.15-beta.0",
"description": "Elasticsearch API for Subsocial blockchain.",
"author": "DappForce contributors",
"license": "GPL-3.0-only",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@subsocial/utils",
"version": "0.8.13",
"version": "0.8.15-beta.0",
"description": "JavaScript utils for Subsocial blockchain.",
"author": "DappForce contributors",
"main": "index.js",
Expand Down
14 changes: 8 additions & 6 deletions packages/utils/src/slugify.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
import { nonEmptyStr } from './string'
import slugify from '@sindresorhus/slugify'
import { summarize } from './summarize'
import memoize from 'lodash/memoize'

const MAX_SLUG_LENGTH = 60
const SLUG_SEPARATOR = '-'

export type HasTitleOrBody = {
title?: string,
title?: string
body: string
}

/** Create slug from the content title or body, appended with the id at the end */
export const createPostSlug = memoize((postId: string, content?: HasTitleOrBody) => {
export const createPostSlug = (postId: string, content?: HasTitleOrBody) => {
let slug: string = '' + postId

if (content) {
const { title, body } = content
const titleOrBody = nonEmptyStr(title) ? title : body
const summary = summarize(titleOrBody, { limit: MAX_SLUG_LENGTH, omission: '' })
const summary = summarize(titleOrBody, {
limit: MAX_SLUG_LENGTH,
omission: ''
})
const slugifiedSummary = slugify(summary, { separator: SLUG_SEPARATOR })

if (nonEmptyStr(slugifiedSummary)) {
slug = slugifiedSummary + '-' + slug
}
}

return slug
})
}

/** Extract post id from the slug generated from `createPostSlug` */
export const getPostIdFromSlug = (slug: string): string | undefined => {
Expand Down

0 comments on commit 5e5546b

Please sign in to comment.