GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — airtable_api/mymap_airtable_api.js at main · smoothnlp/airtable_api Expand file tree/ Copy pathmymap_airtable_api.jsMore file actions 75 lines (67 loc) · 3.15 KB / Copy pathmymap_airtable_api.jsFile metadata and controls75 lines (67 loc) · 3.15 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 /** * Creates a map image based on a template and prompt, and stores the resulting image URL in an Airtable record. * * This function takes a template and a prompt from specified input columns, sends them to an external API * that generates a map image, and then stores the resulting image URL in a specified output column of an Airtable record. * The API request has a timeout of 120 seconds. * * @param {string} tpl_column - The name of the column containing the template value. * @param {string} prompt_column - The name of the column containing the prompt value. * @param {string} output_column - The name of the column where the generated map image URL will be stored. * @param {string} record_id - The ID of the record being processed. * @param {string} table_id - The ID of the table containing the record. * @param {string} base_id - The ID of the Airtable base. * * @throws {Error} Throws an error if no template or prompt is found in the input columns, if the API call fails, or if the request times out. * * @returns {Promise<void>} This function doesn't return a value, but updates the specified record in Airtable. */ async function create_map_image(tpl_column, prompt_column, output_column, record_id, table_id, base_id) { const CREATE_MAP_API_ENDPOINT = 'https://jobs.mymap.ai/jobs/new_map_image/run'; const TIMEOUT = 120000; // 120 seconds in milliseconds // Get the table and record let table = base.getTable(table_id); let record = await table.selectRecordsAsync({ recordIds: [record_id] }); record = record.records[0]; // Get the template and prompt from the input columns let tpl = record.getCellValue(tpl_column); let prompt = record.getCellValue(prompt_column); if (!tpl || !prompt) { console.log(`Missing template or prompt. Template: ${tpl}, Prompt: ${prompt}`); throw new Error("Missing template or prompt"); } try { // Create a promise that rejects in <TIMEOUT> milliseconds const timeoutPromise = new Promise((_, reject) => { const id = setTimeout(() => { clearTimeout(id); reject(new Error(`Request timed out after ${TIMEOUT/1000} seconds`)); }, TIMEOUT); }); // Call the Create Map API with a timeout const fetchPromise = fetch(CREATE_MAP_API_ENDPOINT, { method: 'POST', body: JSON.stringify({ base_id: base_id, table_id: table_id, record_id: record_id, output_column: output_column, visuals: [ { tpl: tpl, prompt: prompt } ] }) }); // Race the fetch promise against the timeout promise const response = await Promise.race([fetchPromise, timeoutPromise]); if (!response.ok) { throw new Error(`API request failed with status ${response.status}`); } console.log("Map image successfully created and URL stored"); } catch (error) { console.error("Error in map image creation:", error); throw error; } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |