Skip to content

k.utils.community

Kooboo community resource sharing and search

Overview

k.utils.community Upload/search/download shared packages (templates, modules, etc., distinguished by type) to the Kooboo community.

shareBinary() / share()

Upload resources: shareBinary uses byte array; share uses Base64 string.

MethodDescription
shareBinary(type, title, description, fileBytes, thumbnailBytes)Upload byte arrays directly
share(type, title, description, binaryBase64, thumbnailBase64)Upload Base64 strings
ParameterTypeRequiredDescription
typestringYesPackage type, such as template or module; max length is 50 characters
titlestringYesCommunity package title
descriptionstringNoPackage description
fileBytesnumber[]YesPackage bytes
thumbnailBytesnumber[]NoThumbnail bytes
binaryBase64stringYesPackage Base64 string
thumbnailBase64stringNoThumbnail Base64 string

Returns: ShareResponse; commonly used fields include isSuccess, isTitleExists, isNotAuthorized, message, and packageId.

ts
const packageBytes = k.file.readBinary("packages/product-template.zip")
const coverBytes = k.file.readBinary("packages/product-template.png")

const result = k.utils.community.shareBinary(
    "template",
    "Product landing template",
    "A reusable product landing page package.",
    packageBytes,
    coverBytes
)

if (!result.isSuccess) {
    throw new Error(result.message || "Share package failed")
}

return result.packageId

Use share() when the package is already encoded as Base64:

ts
const packageBase64 = k.security.toBase64(k.file.readBinary("packages/module.zip"))
const thumbnailBase64 = k.security.toBase64(k.file.readBinary("packages/module.png"))

const result = k.utils.community.share(
    "module",
    "Member tools",
    "Reusable member center scripts.",
    packageBase64,
    thumbnailBase64
)
OverloadDescription
search(type)List by type
search(type, keyword, skip, count)Keyword page search
ParameterTypeRequiredDescription
typestringYesPackage type
keywordstringNoSearch keyword
skipnumberNoNumber of records to skip
countnumberNoNumber of records to return; the simple overload usually returns 30

Returns: CommunityViewModel[].

ts
const firstPage = k.utils.community.search("template", "product", 0, 20)

return firstPage.map(item => ({
    id: item.id,
    title: item.title,
    packageUrl: item.packageUrl
}))

downloadFile()

Press packageUrl to download the package bytes.

ParameterTypeRequiredDescription
packageUrlstringYesPackage URL, starting with http://, https://, or //

Returns: number[], the downloaded file bytes.

ts
const matches = k.utils.community.search("template", "product", 0, 1)
if (matches.length === 0) {
    return null
}

const bytes = k.utils.community.downloadFile(matches[0].packageUrl)
k.file.writeBinary("downloads/community-template.zip", bytes)
return k.file.get("downloads/community-template.zip")

delete()

Delete community entry by Id.

ParameterTypeRequiredDescription
idstringYesCommunity package Id

Returns: DeleteResponse; commonly used fields include isSuccess, isNotAuthorized, isPackageNotFound, and message.

ts
const result = k.utils.community.delete(packageId)
if (!result.isSuccess && !result.isPackageNotFound) {
    throw new Error(result.message || "Delete package failed")
}