From c908e3f7673c1206895401f6537fc59e23336a72 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 27 Sep 2024 18:06:15 +0800 Subject: [PATCH] chore: update --- .eslintcache | 1 + pages/images.vue | 11 +++++++++++ server/api/images.ts | 11 +++++++++++ server/utils/unsplash.ts | 15 +++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 .eslintcache create mode 100644 pages/images.vue create mode 100644 server/api/images.ts create mode 100644 server/utils/unsplash.ts diff --git a/.eslintcache b/.eslintcache new file mode 100644 index 0000000..d38803b --- /dev/null +++ b/.eslintcache @@ -0,0 +1 @@ +[{"/Users/chris/i/chris.me/components/PageHeader.vue":"1","/Users/chris/i/chris.me/components/PersonInfo.vue":"2","/Users/chris/i/chris.me/components/repo/RepoCard.vue":"3","/Users/chris/i/chris.me/pages/projects.vue":"4","/Users/chris/i/chris.me/uno.config.ts":"5"},{"size":279,"mtime":1727418215072,"results":"6","hashOfConfig":"7"},{"size":1662,"mtime":1727416548957,"results":"8","hashOfConfig":"7"},{"size":1974,"mtime":1727418876696,"results":"9","hashOfConfig":"7"},{"size":908,"mtime":1727418883308,"results":"10","hashOfConfig":"7"},{"size":4814,"mtime":1727416347488,"results":"11","hashOfConfig":"12"},{"filePath":"13","messages":"14","suppressedMessages":"15","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"75pghd",{"filePath":"16","messages":"17","suppressedMessages":"18","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"19","messages":"20","suppressedMessages":"21","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"22","messages":"23","suppressedMessages":"24","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"25","messages":"26","suppressedMessages":"27","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"12bxb1y","/Users/chris/i/chris.me/components/PageHeader.vue",[],[],"/Users/chris/i/chris.me/components/PersonInfo.vue",[],[],"/Users/chris/i/chris.me/components/repo/RepoCard.vue",[],[],"/Users/chris/i/chris.me/pages/projects.vue",[],[],"/Users/chris/i/chris.me/uno.config.ts",[],["28"],{"ruleId":"29","severity":2,"message":"30","line":49,"column":9,"nodeType":"31","messageId":"32","endLine":49,"endColumn":18,"suppressions":"33"},"regexp/no-super-linear-backtracking","The quantifier '.+?' can exchange characters with '.+'. Using any string accepted by /:+/, this can be exploited to cause at least polynomial backtracking. This might cause exponential backtracking.","Literal","trade",["34"],{"kind":"35","justification":"36"},"directive",""] \ No newline at end of file diff --git a/pages/images.vue b/pages/images.vue new file mode 100644 index 0000000..962c9a7 --- /dev/null +++ b/pages/images.vue @@ -0,0 +1,11 @@ + + + diff --git a/server/api/images.ts b/server/api/images.ts new file mode 100644 index 0000000..b9423d3 --- /dev/null +++ b/server/api/images.ts @@ -0,0 +1,11 @@ +import { useUnsplash } from '../utils/unsplash' + +export default defineEventHandler(async () => { + if (import.meta.dev) { + const data: any = (await import('~/mock/unsplash.json')).default + return data.response + } + + const res = await useUnsplash().photos.getRandom({ count: 20 }) + return res.response +}) diff --git a/server/utils/unsplash.ts b/server/utils/unsplash.ts new file mode 100644 index 0000000..d64622d --- /dev/null +++ b/server/utils/unsplash.ts @@ -0,0 +1,15 @@ +import fetch from 'node-fetch' +import { createApi } from 'unsplash-js' + +let _unsplash: ReturnType | null = null + +export function useUnsplash() { + if (!_unsplash) { + _unsplash = createApi({ + accessKey: process.env.Unsplash_Access_Key as string, + fetch: fetch as any, + }) + } + + return _unsplash +}