@gallop.software/studio 2.3.39 → 2.3.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/index.js +161 -29
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -1725,26 +1725,134 @@ async function handleMoveStream(request) {
|
|
|
1725
1725
|
const moved = [];
|
|
1726
1726
|
const errors = [];
|
|
1727
1727
|
const sourceFolders = /* @__PURE__ */ new Set();
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
for (
|
|
1731
|
-
const itemPath = paths[i];
|
|
1728
|
+
let totalFiles = 0;
|
|
1729
|
+
const expandedItems = [];
|
|
1730
|
+
for (const itemPath of paths) {
|
|
1732
1731
|
const safePath = itemPath.replace(/\.\./g, "");
|
|
1733
1732
|
const itemName = path6.basename(safePath);
|
|
1734
|
-
const newAbsolutePath = path6.join(absoluteDestination, itemName);
|
|
1735
1733
|
const oldRelativePath = safePath.replace(/^public\/?/, "");
|
|
1736
1734
|
const destWithoutPublic = safeDestination.replace(/^public\/?/, "");
|
|
1737
1735
|
const newRelativePath = destWithoutPublic ? path6.join(destWithoutPublic, itemName) : itemName;
|
|
1738
1736
|
const oldKey = "/" + oldRelativePath;
|
|
1739
1737
|
const newKey = "/" + newRelativePath;
|
|
1738
|
+
const newAbsolutePath = path6.join(absoluteDestination, itemName);
|
|
1739
|
+
const absolutePath = getWorkspacePath(safePath);
|
|
1740
|
+
let hasLocalItem = false;
|
|
1741
|
+
let isDirectory = false;
|
|
1742
|
+
try {
|
|
1743
|
+
const stats = await fs6.stat(absolutePath);
|
|
1744
|
+
hasLocalItem = true;
|
|
1745
|
+
isDirectory = stats.isDirectory();
|
|
1746
|
+
} catch {
|
|
1747
|
+
}
|
|
1748
|
+
if (hasLocalItem && isDirectory) {
|
|
1749
|
+
const countFilesRecursive = async (dir) => {
|
|
1750
|
+
let count = 0;
|
|
1751
|
+
const entries = await fs6.readdir(dir, { withFileTypes: true });
|
|
1752
|
+
for (const entry of entries) {
|
|
1753
|
+
if (entry.isDirectory()) {
|
|
1754
|
+
count += await countFilesRecursive(path6.join(dir, entry.name));
|
|
1755
|
+
} else {
|
|
1756
|
+
count++;
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
return count;
|
|
1760
|
+
};
|
|
1761
|
+
totalFiles += await countFilesRecursive(absolutePath);
|
|
1762
|
+
expandedItems.push({ itemPath, safePath, itemName, oldKey, newKey, newAbsolutePath, isVirtualFolder: false });
|
|
1763
|
+
} else if (!hasLocalItem) {
|
|
1764
|
+
const folderPrefix = oldKey + "/";
|
|
1765
|
+
const virtualItems = [];
|
|
1766
|
+
for (const [key, metaEntry] of Object.entries(meta)) {
|
|
1767
|
+
if (key.startsWith(folderPrefix) && metaEntry && typeof metaEntry === "object") {
|
|
1768
|
+
const relativePath = key.slice(folderPrefix.length);
|
|
1769
|
+
const destNewKey = newKey + "/" + relativePath;
|
|
1770
|
+
virtualItems.push({ oldKey: key, newKey: destNewKey, entry: metaEntry });
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
if (virtualItems.length > 0) {
|
|
1774
|
+
totalFiles += virtualItems.length;
|
|
1775
|
+
expandedItems.push({ itemPath, safePath, itemName, oldKey, newKey, newAbsolutePath, isVirtualFolder: true, virtualFolderItems: virtualItems });
|
|
1776
|
+
sourceFolders.add(absolutePath);
|
|
1777
|
+
} else {
|
|
1778
|
+
totalFiles++;
|
|
1779
|
+
expandedItems.push({ itemPath, safePath, itemName, oldKey, newKey, newAbsolutePath, isVirtualFolder: false });
|
|
1780
|
+
}
|
|
1781
|
+
} else {
|
|
1782
|
+
totalFiles++;
|
|
1783
|
+
expandedItems.push({ itemPath, safePath, itemName, oldKey, newKey, newAbsolutePath, isVirtualFolder: false });
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
sendEvent({ type: "start", total: totalFiles });
|
|
1787
|
+
let processedFiles = 0;
|
|
1788
|
+
for (const expandedItem of expandedItems) {
|
|
1789
|
+
const { itemPath, safePath, itemName, oldKey, newKey, newAbsolutePath, isVirtualFolder, virtualFolderItems } = expandedItem;
|
|
1790
|
+
if (isVirtualFolder && virtualFolderItems) {
|
|
1791
|
+
for (const vItem of virtualFolderItems) {
|
|
1792
|
+
const itemEntry = vItem.entry;
|
|
1793
|
+
const isItemInCloud = itemEntry.c !== void 0;
|
|
1794
|
+
const itemCdnUrl = isItemInCloud ? cdnUrls[itemEntry.c] : void 0;
|
|
1795
|
+
const isItemInR2 = isItemInCloud && itemCdnUrl === r2PublicUrl;
|
|
1796
|
+
const itemHasThumbnails = isProcessed(itemEntry);
|
|
1797
|
+
if (isItemInR2) {
|
|
1798
|
+
try {
|
|
1799
|
+
const itemLocalPath = getPublicPath(vItem.newKey);
|
|
1800
|
+
const buffer = await downloadFromCdn(vItem.oldKey);
|
|
1801
|
+
await fs6.mkdir(path6.dirname(itemLocalPath), { recursive: true });
|
|
1802
|
+
await fs6.writeFile(itemLocalPath, buffer);
|
|
1803
|
+
if (itemHasThumbnails) {
|
|
1804
|
+
const oldThumbPaths = getAllThumbnailPaths(vItem.oldKey);
|
|
1805
|
+
const newThumbPaths = getAllThumbnailPaths(vItem.newKey);
|
|
1806
|
+
for (let t = 0; t < oldThumbPaths.length; t++) {
|
|
1807
|
+
try {
|
|
1808
|
+
const thumbBuffer = await downloadFromCdn(oldThumbPaths[t]);
|
|
1809
|
+
const newThumbLocalPath = getPublicPath(newThumbPaths[t]);
|
|
1810
|
+
await fs6.mkdir(path6.dirname(newThumbLocalPath), { recursive: true });
|
|
1811
|
+
await fs6.writeFile(newThumbLocalPath, thumbBuffer);
|
|
1812
|
+
} catch {
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
await deleteFromCdn(vItem.oldKey, itemHasThumbnails);
|
|
1817
|
+
await uploadOriginalToCdn(vItem.newKey);
|
|
1818
|
+
if (itemHasThumbnails) {
|
|
1819
|
+
await uploadToCdn(vItem.newKey);
|
|
1820
|
+
}
|
|
1821
|
+
try {
|
|
1822
|
+
await fs6.unlink(itemLocalPath);
|
|
1823
|
+
} catch {
|
|
1824
|
+
}
|
|
1825
|
+
if (itemHasThumbnails) {
|
|
1826
|
+
await deleteLocalThumbnails(vItem.newKey);
|
|
1827
|
+
}
|
|
1828
|
+
} catch (err) {
|
|
1829
|
+
console.error(`Failed to move cloud item ${vItem.oldKey}:`, err);
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
delete meta[vItem.oldKey];
|
|
1833
|
+
meta[vItem.newKey] = itemEntry;
|
|
1834
|
+
processedFiles++;
|
|
1835
|
+
sendEvent({
|
|
1836
|
+
type: "progress",
|
|
1837
|
+
current: processedFiles,
|
|
1838
|
+
total: totalFiles,
|
|
1839
|
+
moved: moved.length,
|
|
1840
|
+
percent: Math.round(processedFiles / totalFiles * 100),
|
|
1841
|
+
currentFile: path6.basename(vItem.newKey)
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
moved.push(itemPath);
|
|
1845
|
+
continue;
|
|
1846
|
+
}
|
|
1740
1847
|
if (meta[newKey]) {
|
|
1741
1848
|
errors.push(`${itemName} already exists in destination`);
|
|
1849
|
+
processedFiles++;
|
|
1742
1850
|
sendEvent({
|
|
1743
1851
|
type: "progress",
|
|
1744
|
-
current:
|
|
1745
|
-
total,
|
|
1852
|
+
current: processedFiles,
|
|
1853
|
+
total: totalFiles,
|
|
1746
1854
|
moved: moved.length,
|
|
1747
|
-
percent: Math.round(
|
|
1855
|
+
percent: Math.round(processedFiles / totalFiles * 100),
|
|
1748
1856
|
currentFile: itemName
|
|
1749
1857
|
});
|
|
1750
1858
|
continue;
|
|
@@ -1771,12 +1879,13 @@ async function handleMoveStream(request) {
|
|
|
1771
1879
|
delete meta[oldKey];
|
|
1772
1880
|
meta[newKey] = newEntry;
|
|
1773
1881
|
moved.push(itemPath);
|
|
1882
|
+
processedFiles++;
|
|
1774
1883
|
sendEvent({
|
|
1775
1884
|
type: "progress",
|
|
1776
|
-
current:
|
|
1777
|
-
total,
|
|
1885
|
+
current: processedFiles,
|
|
1886
|
+
total: totalFiles,
|
|
1778
1887
|
moved: moved.length,
|
|
1779
|
-
percent: Math.round(
|
|
1888
|
+
percent: Math.round(processedFiles / totalFiles * 100),
|
|
1780
1889
|
currentFile: itemName
|
|
1781
1890
|
});
|
|
1782
1891
|
} else if (isPushedToR2 && isImage) {
|
|
@@ -1807,24 +1916,26 @@ async function handleMoveStream(request) {
|
|
|
1807
1916
|
delete meta[oldKey];
|
|
1808
1917
|
meta[newKey] = newEntry;
|
|
1809
1918
|
moved.push(itemPath);
|
|
1919
|
+
processedFiles++;
|
|
1810
1920
|
sendEvent({
|
|
1811
1921
|
type: "progress",
|
|
1812
|
-
current:
|
|
1813
|
-
total,
|
|
1922
|
+
current: processedFiles,
|
|
1923
|
+
total: totalFiles,
|
|
1814
1924
|
moved: moved.length,
|
|
1815
|
-
percent: Math.round(
|
|
1925
|
+
percent: Math.round(processedFiles / totalFiles * 100),
|
|
1816
1926
|
currentFile: itemName
|
|
1817
1927
|
});
|
|
1818
1928
|
} else {
|
|
1819
1929
|
const absolutePath = getWorkspacePath(safePath);
|
|
1820
1930
|
if (absoluteDestination.startsWith(absolutePath + path6.sep)) {
|
|
1821
1931
|
errors.push(`Cannot move ${itemName} into itself`);
|
|
1932
|
+
processedFiles++;
|
|
1822
1933
|
sendEvent({
|
|
1823
1934
|
type: "progress",
|
|
1824
|
-
current:
|
|
1825
|
-
total,
|
|
1935
|
+
current: processedFiles,
|
|
1936
|
+
total: totalFiles,
|
|
1826
1937
|
moved: moved.length,
|
|
1827
|
-
percent: Math.round(
|
|
1938
|
+
percent: Math.round(processedFiles / totalFiles * 100),
|
|
1828
1939
|
currentFile: itemName
|
|
1829
1940
|
});
|
|
1830
1941
|
continue;
|
|
@@ -1833,12 +1944,13 @@ async function handleMoveStream(request) {
|
|
|
1833
1944
|
await fs6.access(absolutePath);
|
|
1834
1945
|
} catch {
|
|
1835
1946
|
errors.push(`${itemName} not found`);
|
|
1947
|
+
processedFiles++;
|
|
1836
1948
|
sendEvent({
|
|
1837
1949
|
type: "progress",
|
|
1838
|
-
current:
|
|
1839
|
-
total,
|
|
1950
|
+
current: processedFiles,
|
|
1951
|
+
total: totalFiles,
|
|
1840
1952
|
moved: moved.length,
|
|
1841
|
-
percent: Math.round(
|
|
1953
|
+
percent: Math.round(processedFiles / totalFiles * 100),
|
|
1842
1954
|
currentFile: itemName
|
|
1843
1955
|
});
|
|
1844
1956
|
continue;
|
|
@@ -1846,12 +1958,13 @@ async function handleMoveStream(request) {
|
|
|
1846
1958
|
try {
|
|
1847
1959
|
await fs6.access(newAbsolutePath);
|
|
1848
1960
|
errors.push(`${itemName} already exists in destination`);
|
|
1961
|
+
processedFiles++;
|
|
1849
1962
|
sendEvent({
|
|
1850
1963
|
type: "progress",
|
|
1851
|
-
current:
|
|
1852
|
-
total,
|
|
1964
|
+
current: processedFiles,
|
|
1965
|
+
total: totalFiles,
|
|
1853
1966
|
moved: moved.length,
|
|
1854
|
-
percent: Math.round(
|
|
1967
|
+
percent: Math.round(processedFiles / totalFiles * 100),
|
|
1855
1968
|
currentFile: itemName
|
|
1856
1969
|
});
|
|
1857
1970
|
continue;
|
|
@@ -1887,24 +2000,43 @@ async function handleMoveStream(request) {
|
|
|
1887
2000
|
}
|
|
1888
2001
|
}
|
|
1889
2002
|
moved.push(itemPath);
|
|
2003
|
+
if (stats.isDirectory()) {
|
|
2004
|
+
const countFilesInDir = async (dir) => {
|
|
2005
|
+
let count = 0;
|
|
2006
|
+
const entries = await fs6.readdir(dir, { withFileTypes: true });
|
|
2007
|
+
for (const entry2 of entries) {
|
|
2008
|
+
if (entry2.isDirectory()) {
|
|
2009
|
+
count += await countFilesInDir(path6.join(dir, entry2.name));
|
|
2010
|
+
} else {
|
|
2011
|
+
count++;
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
return count;
|
|
2015
|
+
};
|
|
2016
|
+
const filesInDir = await countFilesInDir(newAbsolutePath);
|
|
2017
|
+
processedFiles += filesInDir;
|
|
2018
|
+
} else {
|
|
2019
|
+
processedFiles++;
|
|
2020
|
+
}
|
|
1890
2021
|
sendEvent({
|
|
1891
2022
|
type: "progress",
|
|
1892
|
-
current:
|
|
1893
|
-
total,
|
|
2023
|
+
current: processedFiles,
|
|
2024
|
+
total: totalFiles,
|
|
1894
2025
|
moved: moved.length,
|
|
1895
|
-
percent: Math.round(
|
|
2026
|
+
percent: Math.round(processedFiles / totalFiles * 100),
|
|
1896
2027
|
currentFile: itemName
|
|
1897
2028
|
});
|
|
1898
2029
|
}
|
|
1899
2030
|
} catch (err) {
|
|
1900
2031
|
console.error(`Failed to move ${itemName}:`, err);
|
|
1901
2032
|
errors.push(`Failed to move ${itemName}`);
|
|
2033
|
+
processedFiles++;
|
|
1902
2034
|
sendEvent({
|
|
1903
2035
|
type: "progress",
|
|
1904
|
-
current:
|
|
1905
|
-
total,
|
|
2036
|
+
current: processedFiles,
|
|
2037
|
+
total: totalFiles,
|
|
1906
2038
|
moved: moved.length,
|
|
1907
|
-
percent: Math.round(
|
|
2039
|
+
percent: Math.round(processedFiles / totalFiles * 100),
|
|
1908
2040
|
currentFile: itemName
|
|
1909
2041
|
});
|
|
1910
2042
|
}
|