Skip to content

Commit 4c62b35

Browse files
author
Michael Liebmann
committed
Repaired URL extraction
1 parent b456419 commit 4c62b35

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/actions/askCodaTable.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ export async function handler({ input }: ActionContext): Promise<OutputObject> {
102102
}
103103

104104
function extractIdsFromUrl(url: string): { docId: string, pageName: string } {
105+
console.log('Extracting IDs from URL:', url);
105106
const urlObj = new URL(url);
107+
console.log('URL object:', urlObj);
106108
const pathParts = urlObj.pathname.split('/').filter(Boolean);
109+
console.log('Path parts:', pathParts);
107110

108111
if (pathParts.length < 2) {
109112
throw new Error('Invalid Coda URL format');
@@ -112,12 +115,22 @@ function extractIdsFromUrl(url: string): { docId: string, pageName: string } {
112115
let docId = '';
113116
let pageName = '';
114117

115-
// Check if the URL is in the format https://coda.io/d/_d{docId}/{pageName}
116-
if (pathParts[0] === 'd' && pathParts[1].startsWith('_d')) {
117-
docId = pathParts[1].slice(2); // Remove '_d' prefix
118-
pageName = pathParts[2] || ''; // Page name is the third part, if present
118+
console.log('First path part:', pathParts[0]);
119+
console.log('Second path part:', pathParts[1]);
120+
121+
if (pathParts[0] === 'd') {
122+
const docIdParts = pathParts[1].split('_');
123+
if (docIdParts.length > 1) {
124+
docId = docIdParts[docIdParts.length - 1]; // Get the last part after splitting by '_'
125+
docId = docId.startsWith('d') ? docId.slice(1) : docId; // Remove leading 'd' if present
126+
pageName = pathParts[2] || ''; // Page name is the third part, if present
127+
console.log('Extracted Doc ID:', docId);
128+
console.log('Extracted Page Name:', pageName);
129+
} else {
130+
throw new Error('Unable to extract Doc ID from the provided URL');
131+
}
119132
} else {
120-
throw new Error('Unable to extract Doc ID from the provided URL');
133+
throw new Error('Invalid Coda URL format');
121134
}
122135

123136
return { docId, pageName };

0 commit comments

Comments
 (0)