MCPcopy Create free account
hub / github.com/VPSDance/ai-proxy-rules / loadSourceText

Function loadSourceText

scripts/sync/build.ts:221–239  ·  view source on GitHub ↗
(
  source: SourceConfig,
  baseDir: string,
  fetcher: Fetcher,
  cache?: ContentCache
)

Source from the content-addressed store, hash-verified

219}
220
221async function loadSourceText(
222 source: SourceConfig,
223 baseDir: string,
224 fetcher: Fetcher,
225 cache?: ContentCache
226): Promise<string> {
227 if (source.type === "local-text") {
228 return readFile(path.resolve(baseDir, source.path), "utf8");
229 }
230
231 if (source.type === "remote-text") {
232 return fetcher(source.url);
233 }
234
235 const cacheKey = `html-extract:${source.url}#${source.selector}`;
236 const fresh = async () => extractHtml(await defaultFetcher(source.url), source.url, source.selector);
237
238 return cache ? cache.cached(cacheKey, fresh) : fresh();
239}
240
241function extractHtml(html: string, url: string, selector: string): string {
242 const $ = load(html);

Callers 1

loadSourceRulesFunction · 0.85

Calls 2

freshFunction · 0.85
cachedMethod · 0.65

Tested by

no test coverage detected