Skip to content

k.utils.community ​

Kooboo community resource sharing and search

Execution ContextPrerequisitesTypical Use
KScript API, platform management scriptsTargets Kooboo Community endpoints; publishing and deleting require platform authSearching/downloading community packages and publishing or deleting packages

k.utils.community uploads, searches, downloads, and deletes shared packages (templates, modules, etc., distinguished by type) in the Kooboo Community.

Scope Note

This module calls Kooboo AppStore/Community endpoints and requires valid platform authentication credentials for publishing or deletion.

Quick Start ​

js
k.api.get("communitySearch", () => {
  const items = k.utils.community.search("template", "product", 0, 10)
  return items.map((item) => ({
    id: item.id,
    title: item.title,
    downloadUrl: item.downloadUrl
  }))
})

Quick Reference ​

Method / PropertyDescriptionReturns
shareBinary(type, title, description, fileBytes, thumbnailBytes)Upload a package and thumbnail as byte arraysShareResponse
share(type, title, description, binaryBase64, thumbnailBase64)Upload a package and thumbnail as Base64 stringsShareResponse
search(type)Search community packages by type (skip=0, count=30)CommunityViewModel[]
search(type, keyword, skip, count)Paginated search by type and keyword (all 4 arguments required)CommunityViewModel[]
downloadFile(packageUrl)Download package bytes from downloadUrlnumber[]
delete(id)Delete a community package by IDDeleteResponse

shareBinary() / share() ​

Upload resources to the community: shareBinary accepts byte arrays, while share accepts Base64 strings.

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, must be non-empty
titlestringYes (positional)Community package title
descriptionstring | nullYes (pass "" or null if none)Package description
fileBytesnumber[]YesPackage bytes (shareBinary only)
thumbnailBytesnumber[] | nullYes (pass null if none)Thumbnail bytes (shareBinary only)
binaryBase64stringYesPackage Base64 string (share only, must be non-empty)
thumbnailBase64string | nullYes (pass "" or null if none)Thumbnail Base64 string (share only)

Positional Argument Requirement

Neither shareBinary nor share has C# default parameter values, so all 5 positional arguments must be provided at runtime; omitting trailing arguments causes overload resolution to fail. Pass "" or null when description or thumbnailBase64 is unused (or null for thumbnailBytes).

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

js
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:

js
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
)

Search community packages by type or paginated keyword query. Only the 1-argument and 4-argument overloads exist and no parameters have default values; calling search() with 2 or 3 arguments fails overload resolution at runtime.

OverloadDescription
search(type)List by type (delegates to search(type, null, 0, 30), always querying skip=0, count=30)
search(type, keyword, skip, count)Keyword paginated search (all 4 arguments must be provided)
ParameterTypeRequiredDescription
typestringYesPackage type
keywordstring | nullRequired in 4-arg overload (pass "" or null if unused)Search keyword
skipnumberRequired in 4-arg overloadNumber of records to skip (applied when > 0)
countnumberRequired in 4-arg overloadNumber of records to return (applied when > 0)

Returns: CommunityViewModel[].

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

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

CommunityViewModel Properties ​

PropertyTypeDescription
idanyPackage ID
typestringPackage type
titlestringTitle
userNamestringAuthor user name
descriptionstringDescription
rankingnumberRanking score
creationDateDateCreation date
downloadCountnumberDownload count
thumbNailExtensionstringThumbnail extension
pricenumberPrice
thumbNailUrlstringThumbnail URL
downloadUrlstringPackage download URL

downloadFile() ​

Download package bytes from downloadUrl.

ParameterTypeRequiredDescription
packageUrlstringYesPackage URL (typically CommunityViewModel.downloadUrl), starting with http://, https://, or //

Returns: number[], the downloaded file bytes.

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

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

delete() ​

Delete a community entry by ID.

ParameterTypeRequiredDescription
idstringYesCommunity package ID

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

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

TypeScript Definitions ​

Show full TypeScript definitions
ts
interface KCommunity {
  shareBinary(type: string, title: string, description: string | null, FileBinary: number[], ThumbnailBinary: number[] | null): ShareResponse;
  share(type: string, Title: string, Description: string | null, BinaryBase64: string, ThumbnailBase64: string | null): ShareResponse;
  search(type: string): CommunityViewModel[];
  search(type: string, keyword: string | null, skip: number, count: number): CommunityViewModel[];
  downloadFile(packageUrl: string): number[];
  delete(Id: string): DeleteResponse;
}

interface ShareResponse {
  isSuccess: boolean;
  isTitleExists: boolean;
  isNotAuthorized: boolean;
  message: string;
  packageId: any;
}

interface DeleteResponse {
  isSuccess: boolean;
  isNotAuthorized: boolean;
  isPackageNotFound: boolean;
  message: string;
}

interface CommunityViewModel {
  id: any;
  type: string;
  title: string;
  userName: string;
  description: string;
  ranking: number;
  creationDate: Date;
  downloadCount: number;
  thumbNailExtension: string;
  price: number;
  thunbnailUrl: string;
  thumbNailUrl: string;
  downloadUrl: string;
}