Skip to content

Commit 381b40b

Browse files
committed
feat(filesystem): add recursive option to CreateFolder action
1 parent 36cb637 commit 381b40b

3 files changed

Lines changed: 116 additions & 108 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ The main files you may want to look at would be instance.js
5757
| Copy file | Copies the file. | Source *(string)* <br>Destination *(string)* <br>Overwrite *(boolean)* <br> |
5858
| Fetch file size (synchronous) | Fetch the size of the file. (synchronous) | Path *(string)* <br>Tag *(string)* <br> |
5959
| Fetch file size | Fetch the size of the file. | Path *(string)* <br> |
60-
| Create folder (synchronous) | Creates the folder. (synchronous) | Path *(string)* <br>Tag *(string)* <br> |
61-
| Create folder | Creates the folder. | Path *(string)* <br> |
60+
| Create folder (synchronous) | Creates the folder. (synchronous) | Path *(string)* <br>Recursive *(boolean)* <br>Tag *(string)* <br> |
61+
| Create folder | Creates the folder. | Path *(string)* <br>Recursive *(boolean)* <br> |
6262
| Delete file (synchronous) | Deletes the file. (synchronous) | Path *(string)* <br>Recursive *(boolean)* <br>Tag *(string)* <br> |
6363
| Delete file | Deletes the file. | Path *(string)* <br>Recursive *(boolean)* <br> |
6464
| List files (synchronous) | Load a list of files in a given folder. Use expressions after this action to get the count and file names (synchronous) | Path *(string)* <br>Recursive *(boolean)* <br>Tag *(string)* <br> |

src/instance.js

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,11 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
455455

456456
this?.addLoadPromise?.(
457457
this.postToDOMAsync("get-fullscreen-state")
458-
.then(
459-
/** @type {import("./sdk.js").PostFullscreenState} */
460-
data =>
461-
{
462-
this._fullscreenState = data.state
463-
})
458+
.then(
459+
/** @type {import("./sdk.js").PostFullscreenState} */
460+
data => {
461+
this._fullscreenState = data.state
462+
})
464463
);
465464

466465
this.addDOMMessageHandler('fullscreen-state-changed', (data) => {
@@ -1341,14 +1340,16 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
13411340

13421341
_CreateFolderBase = this.wrap(super._CreateFolder, async (
13431342
/** @type {string} */ path,
1343+
/** @type {boolean} */ recursive,
13441344
/** @type {Tag} */ tag,
13451345
) => {
13461346
try {
13471347
/** @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessageCreateFolder, 'input'>} */
13481348
const order = {
13491349
url: '/fs/folder/create',
13501350
body: {
1351-
path
1351+
path,
1352+
recursive,
13521353
}
13531354
}
13541355

@@ -1990,7 +1991,7 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
19901991
let result = []
19911992
if (target) {
19921993
if (target.height === 1) {
1993-
const { width } = target;
1994+
const { width } = target;
19941995
for (let i = 0; i < width; i++) {
19951996
const value = target.getAt(i)
19961997

@@ -2227,7 +2228,7 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
22272228
// Map Construct3 combo values to Steam constants
22282229
// 0 = "none", 1 = "addToCartAndShow"
22292230
const steamFlag = flag === 1 ? 2 : 0; // k_EOverlayToStoreFlag_AddToCartAndShow : k_EOverlayToStoreFlag_None
2230-
2231+
22312232
/** @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').SteamRaw<'overlay', 'activateToStore'>, 'input'>} */
22322233
const order = {
22332234
url: '/steam/raw',
@@ -2462,32 +2463,32 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
24622463
// Build updateDetails object with only the fields that should be updated
24632464
/** @type {Record<string, any>} */
24642465
const updateDetails = {}
2465-
2466+
24662467
if (updateTitle) {
24672468
updateDetails.title = title
24682469
}
2469-
2470+
24702471
if (updateDescription) {
24712472
updateDetails.description = description
24722473
}
2473-
2474+
24742475
if (updateContent) {
24752476
updateDetails.contentPath = contentFolderPath
24762477
}
2477-
2478+
24782479
if (updatePreview) {
24792480
updateDetails.previewPath = previewImagePath
24802481
}
2481-
2482+
24822483
if (updateTags) {
24832484
const tagArray = tags.split(',').map(t => t.trim()).filter(t => t.length > 0)
24842485
updateDetails.tags = tagArray
24852486
}
2486-
2487+
24872488
if (updateVisibility) {
24882489
updateDetails.visibility = visibility
24892490
}
2490-
2491+
24912492
if (changeNote) {
24922493
updateDetails.changeNote = changeNote
24932494
}
@@ -2549,10 +2550,10 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
25492550
if (subscribedAnswer?.body.success === false) {
25502551
throw new Error('Failed to get subscribed items')
25512552
}
2552-
2553+
25532554
const itemIds = subscribedAnswer?.body.data ?? []
25542555
this._subscribedItemIds = itemIds.map(id => id.toString())
2555-
2556+
25562557
if (itemIds.length === 0) {
25572558
this._GetSubscribedItemsWithMetadataErrorValue = ''
25582559
await this.trigger(tag, [
@@ -2577,22 +2578,22 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
25772578

25782579
// @ts-expect-error - API returns WorkshopItemsResult
25792580
const items = metadataAnswer?.body.data?.items ?? []
2580-
2581+
25812582
// Store items in map and get state/install/download info for each
25822583
for (const item of items) {
25832584
if (!item) continue
25842585
const itemIdStr = item.publishedFileId.toString()
2585-
2586+
25862587
// Get state and install info using helper functions
25872588
const state = await this._getItemState(item.publishedFileId)
25882589
const installInfo = await this._getItemInstallInfo(item.publishedFileId)
2589-
2590+
25902591
// Get download info if downloading
25912592
let downloadInfo = null
25922593
if (state && (state & 16)) {
25932594
downloadInfo = await this._getItemDownloadInfo(item.publishedFileId)
25942595
}
2595-
2596+
25962597
// Store combined data
25972598
this._workshopItemsMap.set(itemIdStr, {
25982599
...item,
@@ -2923,12 +2924,12 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
29232924

29242925
// @ts-expect-error - API returns WorkshopItem
29252926
const item = answer?.body.data
2926-
2927+
29272928
if (item) {
29282929
const itemIdStr = item.publishedFileId.toString()
29292930
const existingItem = this._workshopItemsMap.get(itemIdStr)
29302931
if (existingItem) {
2931-
this._workshopItemsMap.set(itemIdStr, {...existingItem, ... item})
2932+
this._workshopItemsMap.set(itemIdStr, { ...existingItem, ...item })
29322933
} else {
29332934
this._workshopItemsMap.set(itemIdStr, item)
29342935
}
@@ -2958,7 +2959,7 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
29582959
) => {
29592960
try {
29602961
const itemIdArray = itemIds.split(',').map(id => id.trim()).filter(id => id.length > 0)
2961-
2962+
29622963
if (itemIdArray.length === 0) {
29632964
this._GetWorkshopItemsErrorValue = ''
29642965
await this.trigger(tag, [
@@ -2982,13 +2983,13 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
29822983

29832984
// @ts-expect-error - API returns WorkshopItemsResult
29842985
const items = answer?.body.data?.items ?? []
2985-
2986+
29862987
for (const item of items) {
29872988
if (!item) continue
29882989
const itemIdStr = item.publishedFileId.toString()
29892990
const existingItem = this._workshopItemsMap.get(itemIdStr)
29902991
if (existingItem) {
2991-
this._workshopItemsMap.set(itemIdStr, {...existingItem, ... item})
2992+
this._workshopItemsMap.set(itemIdStr, { ...existingItem, ...item })
29922993
} else {
29932994
this._workshopItemsMap.set(itemIdStr, item)
29942995
}
@@ -3029,10 +3030,10 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
30293030
if (answer?.body.success === false) {
30303031
throw new Error('Failed to get subscribed items')
30313032
}
3032-
3033+
30333034
const itemIds = answer?.body.data ?? []
30343035
this._subscribedItemIds = itemIds.map(id => id.toString())
3035-
3036+
30363037
this._GetSubscribedWorkshopItemsErrorValue = ''
30373038
await this.trigger(tag, [
30383039
C3.Plugins.pipelabv2.Cnds.OnGetSubscribedWorkshopItemsSuccess,
@@ -3071,20 +3072,20 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
30713072

30723073
// @ts-expect-error - API returns WorkshopItem
30733074
const item = answer?.body.data
3074-
3075+
30753076
if (item) {
30763077
const itemIdStr = item.publishedFileId.toString()
3077-
3078+
30783079
// Get state and install info
30793080
const state = await this._getItemState(item.publishedFileId)
30803081
const installInfo = await this._getItemInstallInfo(item.publishedFileId)
3081-
3082+
30823083
// Get download info if downloading
30833084
let downloadInfo = null
30843085
if (state && (state & 16)) {
30853086
downloadInfo = await this._getItemDownloadInfo(item.publishedFileId)
30863087
}
3087-
3088+
30883089
// Store combined data
30893090
this._workshopItemsMap.set(itemIdStr, {
30903091
...item,
@@ -3118,7 +3119,7 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
31183119
) => {
31193120
try {
31203121
const itemIdArray = itemIds.split(',').map(id => id.trim()).filter(id => id.length > 0)
3121-
3122+
31223123
if (itemIdArray.length === 0) {
31233124
this._GetWorkshopItemsWithMetadataErrorValue = ''
31243125
await this.trigger(tag, [
@@ -3143,22 +3144,22 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
31433144

31443145
// @ts-expect-error - API returns WorkshopItemsResult
31453146
const items = answer?.body.data?.items ?? []
3146-
3147+
31473148
// Get state/install/download info for each item
31483149
for (const item of items) {
31493150
if (!item) continue
31503151
const itemIdStr = item.publishedFileId.toString()
3151-
3152+
31523153
// Get state and install info
31533154
const state = await this._getItemState(item.publishedFileId)
31543155
const installInfo = await this._getItemInstallInfo(item.publishedFileId)
3155-
3156+
31563157
// Get download info if downloading
31573158
let downloadInfo = null
31583159
if (state && (state & 16)) {
31593160
downloadInfo = await this._getItemDownloadInfo(item.publishedFileId)
31603161
}
3161-
3162+
31623163
// Store combined data
31633164
this._workshopItemsMap.set(itemIdStr, {
31643165
...item,

0 commit comments

Comments
 (0)