k.utils.community
Kooboo community resource sharing and search
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
| KScript API, platform management scripts | Targets Kooboo Community endpoints; publishing and deleting require platform auth | Searching/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
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 / Property | Description | Returns |
|---|---|---|
shareBinary(type, title, description, fileBytes, thumbnailBytes) | Upload a package and thumbnail as byte arrays | ShareResponse |
share(type, title, description, binaryBase64, thumbnailBase64) | Upload a package and thumbnail as Base64 strings | ShareResponse |
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 downloadUrl | number[] |
delete(id) | Delete a community package by ID | DeleteResponse |
shareBinary() / share()
Upload resources to the community: shareBinary accepts byte arrays, while share accepts Base64 strings.
| Method | Description |
|---|---|
shareBinary(type, title, description, fileBytes, thumbnailBytes) | Upload byte arrays directly |
share(type, title, description, binaryBase64, thumbnailBase64) | Upload Base64 strings |
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Package type, such as template or module; max length is 50 characters, must be non-empty |
title | string | Yes (positional) | Community package title |
description | string | null | Yes (pass "" or null if none) | Package description |
fileBytes | number[] | Yes | Package bytes (shareBinary only) |
thumbnailBytes | number[] | null | Yes (pass null if none) | Thumbnail bytes (shareBinary only) |
binaryBase64 | string | Yes | Package Base64 string (share only, must be non-empty) |
thumbnailBase64 | string | null | Yes (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.
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.packageIdUse share() when the package is already encoded as Base64:
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()
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.
| Overload | Description |
|---|---|
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) |
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Package type |
keyword | string | null | Required in 4-arg overload (pass "" or null if unused) | Search keyword |
skip | number | Required in 4-arg overload | Number of records to skip (applied when > 0) |
count | number | Required in 4-arg overload | Number of records to return (applied when > 0) |
Returns: CommunityViewModel[].
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
| Property | Type | Description |
|---|---|---|
id | any | Package ID |
type | string | Package type |
title | string | Title |
userName | string | Author user name |
description | string | Description |
ranking | number | Ranking score |
creationDate | Date | Creation date |
downloadCount | number | Download count |
thumbNailExtension | string | Thumbnail extension |
price | number | Price |
thumbNailUrl | string | Thumbnail URL |
downloadUrl | string | Package download URL |
downloadFile()
Download package bytes from downloadUrl.
| Parameter | Type | Required | Description |
|---|---|---|---|
packageUrl | string | Yes | Package URL (typically CommunityViewModel.downloadUrl), starting with http://, https://, or // |
Returns: number[], the downloaded file bytes.
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.
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Community package ID |
Returns: DeleteResponse; commonly used fields include isSuccess, isNotAuthorized, isPackageNotFound, and message.
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
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;
}