-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery-builder.ts
More file actions
75 lines (66 loc) · 2.38 KB
/
Copy pathquery-builder.ts
File metadata and controls
75 lines (66 loc) · 2.38 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
/* eslint-disable no-console */
import { QueryBuilder } from 'mdfind-node'
import { homedir } from 'os'
import { join } from 'path'
async function main() {
try {
// Example 1: Find high-resolution photos taken with a specific camera
console.log('1. Finding high-resolution photos taken with a Canon camera:')
const photoQuery = new QueryBuilder()
.contentType('public.image')
.takenWith('Canon')
.minImageDimensions(3000, 2000)
.inDirectory(join(homedir(), 'Pictures'))
const photos = await photoQuery.execute()
console.log(`Found ${photos.length} photos`)
console.log(
'First 3:',
photos.slice(0, 3).map((p: string) => p.split('/').pop())
)
// Example 2: Find high-quality audio files by an artist
console.log('\n2. Finding high-quality audio files by an artist:')
const audioQuery = new QueryBuilder()
.contentType('public.audio')
.author('Radiohead')
.minAudioQuality(44100, 320000)
const audioFiles = await audioQuery.execute()
console.log(`Found ${audioFiles.length} audio files`)
console.log(
'First 3:',
audioFiles.slice(0, 3).map((p: string) => p.split('/').pop())
)
// Example 3: Find PDF documents with specific keywords
console.log('\n3. Finding PDF documents about TypeScript:')
const docQuery = new QueryBuilder()
.isPDF()
.hasKeyword('typescript')
.inDirectory(join(homedir(), 'Documents'))
const docs = await docQuery.execute()
console.log(`Found ${docs.length} documents`)
console.log(
'First 3:',
docs.slice(0, 3).map((p: string) => p.split('/').pop())
)
// Example 4: Find recently modified code files
console.log('\n4. Finding recently modified code files:')
const codeQuery = new QueryBuilder()
.isText()
.modifiedAfter(new Date(Date.now() - 24 * 60 * 60 * 1000)) // Last 24 hours
.extension('ts')
.inDirectory(process.cwd()) // Only search in current project
.maxBuffer(10 * 1024 * 1024) // 10MB buffer
const codeFiles = await codeQuery.execute()
console.log(`Found ${codeFiles.length} code files`)
console.log(
'First 3:',
codeFiles.slice(0, 3).map((p: string) => p.split('/').pop())
)
} catch (error) {
console.error('Error:', error)
process.exit(1)
}
}
main().catch(error => {
console.error('Unhandled error:', error)
process.exit(1)
})