1/** 2 * WorksApi: æ½å·¥äºä¾ï¼Worksï¼é¢é£ã®APIã¯ã©ã¤ã¢ã³ã 3 * 4 * CmsApiã使ç¨ãã¦ãworksåºæã®ã¨ã³ããã¤ã³ããå¼ã³åºãã 5 */ 6(function () { 7 'use strict'; 8 9 if (!window.CmsApi) { 10 return; 11 } 12 13 const { fetchList, fetchDetail, buildHeaders } = window.CmsApi; 14 const CMS_NAME = 'works'; 15 16 /** 17 * æ½å·¥äºä¾ä¸è¦§ãåå¾ 18 * @param {Object} params ãã©ã¡ã¼ã¿ãªãã¸ã§ã¯ã 19 * @param {string} [params.symfonyApiUrl] APIã®ãã¼ã¹URLï¼çç¥æã¯ããã©ã«ãè¨å®ããåå¾ï¼ 20 * @param {number} [params.page=1] ãã¼ã¸çªå· 21 * @param {number} [params.limit=8] åå¾ä»¶æ° 22 * @param {string|null} [params.storeSlug=null] åºèã®ã¹ã©ã° 23 * @param {number[]} [params.conditionFilters=[]] æ¡ä»¶ãã£ã«ã¿ã¼IDã®é å 24 * @param {number[]} [params.designFilters=[]] ãã¶ã¤ã³ãã£ã«ã¿ã¼IDã®é å 25 * @returns {Promise<{data: Array, pagination: object}|{error: string}>} 26 */ 27 async function fetchWorksList(params = {}) { 28 const { 29 symfonyApiUrl = window.withdomCommonConfig?.symfonyApiUrl || '', 30 page = 1, 31 limit = 8, 32 storeSlug = null, 33 conditionFilters = [], 34 designFilters = [] 35 } = params; 36 37 const queryParams = {}; 38 if (storeSlug) { 39 queryParams.storeSlug = storeSlug; 40 } 41 if (conditionFilters && Array.isArray(conditionFilters) && conditionFilters.length > 0) { 42 queryParams.conditionFilters = conditionFilters; 43 } 44 if (designFilters && Array.isArray(designFilters) && designFilters.length > 0) { 45 queryParams.designFilters = designFilters; 46 } 47 48 return fetchList(CMS_NAME, { 49 symfonyApiUrl: symfonyApiUrl, 50 page: page, 51 limit: limit, 52 queryParams: queryParams 53 }); 54 } 55 56 /** 57 * æ½å·¥äºä¾è©³ç´°ãåå¾ 58 * @param {number|string} id æ½å·¥äºä¾ID 59 * @param {Object} params ãã©ã¡ã¼ã¿ãªãã¸ã§ã¯ã 60 * @param {string} [params.symfonyApiUrl] APIã®ãã¼ã¹URLï¼çç¥æã¯ããã©ã«ãè¨å®ããåå¾ï¼ 61 * @returns {Promise<{data: object}|{error: string}>} 62 */ 63 async function fetchWorksDetail(id, params = {}) { 64 const { 65 symfonyApiUrl = window.withdomCommonConfig?.symfonyApiUrl || '' 66 } = params; 67 68 return fetchDetail(CMS_NAME, id, { 69 symfonyApiUrl: symfonyApiUrl, 70 queryParams: {} 71 }); 72 } 73 74 /** 75 * ãã£ã«ã¿ã¼ä¸è¦§ãåå¾ï¼æ¡ä»¶ãã£ã«ã¿ã¼ã¨ãã¶ã¤ã³ãã£ã«ã¿ã¼ãã¾ã¨ãã¦åå¾ï¼ 76 * @param {Object} params ãã©ã¡ã¼ã¿ãªãã¸ã§ã¯ã 77 * @param {string} [params.symfonyApiUrl] APIã®ãã¼ã¹URLï¼çç¥æã¯ããã©ã«ãè¨å®ããåå¾ï¼ 78 * @returns {Promise<{condition: Array, design: Array}|{error: string}>} 79 */ 80 async function fetchWorksFilters(params = {}) { 81 const { 82 symfonyApiUrl = window.withdomCommonConfig?.symfonyApiUrl || '' 83 } = params; 84 85 if (!symfonyApiUrl) { 86 return { error: 'API URL ãè¨å®ããã¦ãã¾ããã' }; 87 } 88 89 const apiUrl = `${symfonyApiUrl}/api/works/filters`; 90 91 try { 92 const response = await fetch(apiUrl, { 93 method: 'GET', 94 headers: buildHeaders() 95 }); 96 97 if (!response.ok) { 98 console.error('[ãã£ã«ã¿ã¼ã®åå¾ã«å¤±æãã¾ãã]', { 99 status: response.status, 100 statusText: response.statusText, 101 url: apiUrl 102 }); 103 return { error: 'ãã£ã«ã¿ã¼ã®åå¾ã«å¤±æãã¾ããã' }; 104 } 105 106 const result = await response.json(); 107 108 if (result.error) { 109 return { error: result.error }; 110 } 111 112 return { 113 condition: result.condition || [], 114 design: result.design || [] 115 }; 116 } catch (error) { 117 console.error('[ãã£ã«ã¿ã¼ã®åå¾ä¸ã«ã¨ã©ã¼ãçºçãã¾ãã]', { 118 error: error, 119 message: error.message, 120 name: error.name, 121 url: apiUrl 122 }); 123 return { error: 'ãã£ã«ã¿ã¼ã®åå¾ä¸ã«ã¨ã©ã¼ãçºçãã¾ããã' }; 124 } 125 } 126 127 /** 128 * ä»¶æ°ãåå¾ 129 * @param {Object} params ãã©ã¡ã¼ã¿ãªãã¸ã§ã¯ã 130 * @param {string} [params.symfonyApiUrl] APIã®ãã¼ã¹URLï¼çç¥æã¯ããã©ã«ãè¨å®ããåå¾ï¼ 131 * @param {string|null} [params.storeSlug=null] åºèã®ã¹ã©ã° 132 * @param {Object} [params.conditionFilters={}] æ¡ä»¶ãã£ã«ã¿ã¼ï¼{type: id}å½¢å¼ï¼ 133 * @param {number[]} [params.designFilters=[]] ãã¶ã¤ã³ãã£ã«ã¿ã¼IDã®é å 134 * @returns {Promise<{count: number}|{error: string}>} 135 */ 136 async function fetchWorksCount(params = {}) { 137 const { 138 symfonyApiUrl = window.withdomCommonConfig?.symfonyApiUrl || '', 139 storeSlug = null, 140 conditionFilters = {}, 141 designFilters = [] 142 } = params; 143 144 if (!symfonyApiUrl) { 145 return { error: 'API URL ãè¨å®ããã¦ãã¾ããã' }; 146 } 147 148 const queryParams = new URLSearchParams(); 149 if (storeSlug) { 150 queryParams.set('storeSlug', storeSlug); 151 } 152 153 // conditionFilter[type]=idå½¢å¼ã§è¿½å
154 Object.keys(conditionFilters).forEach(type => { 155 if (conditionFilters[type]) { 156 queryParams.append(`conditionFilters[${type}]`, conditionFilters[type]); 157 } 158 }); 159 160 // designFilters[]å½¢å¼ã§è¿½å 161 designFilters.forEach(id => { 162 if (id) { 163 queryParams.append('designFilters[]', id); 164 } 165 }); 166 167 const apiUrl = `${symfonyApiUrl}/api/works/count${queryParams.toString() ? '?' + queryParams.toString() : ''}`; 168 169 try { 170 const response = await fetch(apiUrl, { 171 method: 'GET', 172 headers: buildHeaders() 173 }); 174 175 if (!response.ok) { 176 console.error('[ä»¶æ°ã®åå¾ã«å¤±æãã¾ãã]', { 177 status: response.status, 178 statusText: response.statusText, 179 url: apiUrl 180 }); 181 return { error: 'ä»¶æ°ã®åå¾ã«å¤±æãã¾ããã' }; 182 } 183 184 const count = await response.json(); 185 return { count: typeof count === 'number' ? count : parseInt(count, 10) || 0 }; 186 } catch (error) { 187 console.error('[ä»¶æ°ã®åå¾ä¸ã«ã¨ã©ã¼ãçºçãã¾ãã]', { 188 error: error, 189 message: error.message, 190 name: error.name, 191 url: apiUrl 192 }); 193 return { error: 'ä»¶æ°ã®åå¾ä¸ã«ã¨ã©ã¼ãçºçãã¾ããã' }; 194 } 195 } 196 197 // ã°ãã¼ãã«ã«å ¬é 198 window.WorksApi = { 199 fetchWorksList, 200 fetchWorksDetail, 201 fetchWorksFilters, 202 fetchWorksCount 203 }; 204})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.