MCPcopy Create free account
hub / github.com/parse-community/parse-dashboard / getScripts

Method getScripts

src/lib/ScriptManager.js:28–82  ·  view source on GitHub ↗

* Gets scripts from either server or local storage based on configuration and user preference * @param {string} appId - The application ID * @returns {Promise } Array of scripts

(appId)

Source from the content-addressed store, hash-verified

26 * @returns {Promise<Array>} Array of scripts
27 */
28 async getScripts(appId) {
29 // Check if server storage is enabled and user prefers it
30 if (this.serverStorage.isServerConfigEnabled() && prefersServerStorage(appId)) {
31 try {
32 const serverScripts = await this._getScriptsFromServer(appId);
33 // Always return server scripts (even if empty) when server storage is preferred
34 return serverScripts || [];
35 } catch (error) {
36 console.error('Failed to get scripts from server:', error);
37 // When server storage is preferred, return empty array instead of falling back to local
38 return [];
39 }
40 }
41
42 // Use local storage when server storage is not preferred
43 let localScripts = this._getScriptsFromLocal(appId);
44
45 // Always check for legacy single-script format and add it as a new unsaved tab
46 const legacyScript = this._getScriptFromLegacySingleFormat();
47 if (legacyScript && legacyScript.length > 0) {
48 // Check if a script with the same code already exists to prevent duplicates
49 const legacyScriptData = legacyScript[0];
50 const existingScript = (localScripts || []).find(script =>
51 script.code === legacyScriptData.code && script.name === 'Legacy Script'
52 );
53
54 if (!existingScript) {
55 // Assign order property to automatically open the legacy script as a tab
56 // Use order 0 to make it the first tab
57 legacyScriptData.order = 0;
58
59 // Mark as saved to prevent unnecessary unsaved change warnings
60 legacyScriptData.saved = true;
61
62 // If we have existing scripts, add the legacy script to them
63 if (localScripts && localScripts.length > 0) {
64 // Increment order of existing scripts to make room for legacy script at position 0
65 localScripts.forEach(script => {
66 if (script.order !== undefined && script.order !== null) {
67 script.order += 1;
68 }
69 });
70 localScripts = [...localScripts, ...legacyScript];
71 } else {
72 // If no existing scripts, use the legacy script
73 localScripts = legacyScript;
74 }
75
76 // Auto-save the legacy script to storage
77 this._saveScriptsToLocal(appId, localScripts);
78 }
79 }
80
81 return localScripts || [];
82 }
83
84 /**
85 * Gets only the scripts that should be open (have an order property)

Callers 8

getOpenScriptsMethod · 0.95
getAllSavedScriptsMethod · 0.95
openScriptMethod · 0.95
closeScriptMethod · 0.95
updateScriptOrderMethod · 0.95
deleteScriptMethod · 0.95
loadDataFunction · 0.80

Calls 6

_getScriptsFromServerMethod · 0.95
_getScriptsFromLocalMethod · 0.95
_saveScriptsToLocalMethod · 0.95
prefersServerStorageFunction · 0.90
isServerConfigEnabledMethod · 0.45

Tested by

no test coverage detected