Skip to content

Commit

Permalink
fix: require auth token with getImageMeta and getTextAssetContent
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Nov 27, 2023
1 parent 4abd280 commit 69316c4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/devtools-kit/src/_types/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export interface ServerFunctions {
clearAnalyzeBuilds(token: string, names?: string[]): Promise<void>

// Queries
getImageMeta(filepath: string): Promise<ImageMeta | undefined>
getTextAssetContent(filepath: string, limit?: number): Promise<string | undefined>
getImageMeta(token: string, filepath: string): Promise<ImageMeta | undefined>
getTextAssetContent(token: string, filepath: string, limit?: number): Promise<string | undefined>
writeStaticAssets(token: string, file: AssetEntry[], folder: string): Promise<string[]>
deleteStaticAsset(token: string, filepath: string): Promise<void>
renameStaticAsset(token: string, oldPath: string, newPath: string): Promise<void>
Expand Down
8 changes: 3 additions & 5 deletions packages/devtools/client/components/AssetDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ const props = defineProps<{
const emit = defineEmits<{ (...args: any): void }>()
const asset = useVModel(props, 'modelValue', emit, { passive: true })
const openInEditor = useOpenInEditor()
const imageMeta = computedAsync(() => {
const imageMeta = computedAsync(async () => {
if (asset.value.type !== 'image')
return undefined
return rpc.getImageMeta(asset.value.filePath)
return rpc.getImageMeta(await ensureDevAuthToken(), asset.value.filePath)
})
const editDialog = ref(false)
Expand All @@ -27,7 +25,7 @@ const textContent = computedAsync(async () => {
// eslint-disable-next-line no-unused-expressions
textContentCounter.value
const content = await rpc.getTextAssetContent(asset.value.filePath)
const content = await rpc.getTextAssetContent(await ensureDevAuthToken(), asset.value.filePath)
newTextContent.value = content
return content
})
Expand Down
8 changes: 6 additions & 2 deletions packages/devtools/src/server-rpc/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export function setupAssetsRPC({ nuxt, ensureDevAuthToken, refresh, options }: N
async getStaticAssets() {
return await scan()
},
async getImageMeta(filepath: string) {
async getImageMeta(token: string, filepath: string) {
await ensureDevAuthToken(token)

if (_imageMetaCache.has(filepath))
return _imageMetaCache.get(filepath)
try {
Expand All @@ -83,7 +85,9 @@ export function setupAssetsRPC({ nuxt, ensureDevAuthToken, refresh, options }: N
return undefined
}
},
async getTextAssetContent(filepath: string, limit = 300) {
async getTextAssetContent(token: string, filepath: string, limit = 300) {
await ensureDevAuthToken(token)

try {
const content = await fsp.readFile(filepath, 'utf-8')
return content.slice(0, limit)
Expand Down

0 comments on commit 69316c4

Please sign in to comment.