-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhms.js
127 lines (114 loc) · 4.03 KB
/
hms.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const API = {
async getSiteInfo(endpoint) {
try {
const response = await fetch(`${endpoint}site`)
if (!response.ok) throw new Error(`HTTP error: ${response.status}`)
return await response.json()
} catch (error) {
console.error('Error fetching site info:', error)
}
},
async getItems(endpoint) {
try {
const response = await fetch(`${endpoint}items`)
if (!response.ok) throw new Error(`HTTP error: ${response.status}`)
return await response.json()
} catch (error) {
console.error('Error fetching items:', error)
}
},
async getItemsInCollection(collectionEndpoint) {
try {
const response = await fetch(collectionEndpoint)
if (!response.ok) throw new Error(`HTTP error: ${response.status}`)
return await response.json()
} catch (error) {
console.error('Error fetching items in collection:', error)
}
},
hasItems(itemList) {
return Array.isArray(itemList) && itemList.length > 0
},
async getItemMetadata(endpoint, id) {
if (typeof id !== 'number') throw new Error('The value provided must be an id.')
try {
const response = await fetch(`${endpoint}items/${id}`)
if (!response.ok) throw new Error(`HTTP error: ${response.status}`)
return await response.json()
} catch (error) {
console.error('Error fetching item metadata:', error)
}
},
async getFilesInItem(endpoint, id) {
try {
const item = await this.getItemMetadata(endpoint, id)
const response = await fetch(item.files.url)
if (!response.ok) throw new Error(`HTTP error: ${response.status}`)
return await response.json()
} catch (error) {
console.error('Error fetching files in item:', error)
}
},
async getCollections(endpoint) {
try {
const response = await fetch(`${endpoint}collections`)
if (!response.ok) throw new Error(`HTTP error: ${response.status}`)
return await response.json()
} catch (error) {
console.error('Error fetching collections:', error)
}
},
hasCollections(collectionList) {
return Array.isArray(collectionList) && collectionList.length > 0
},
async getCollectionMetadataById(endpoint, id) {
if (typeof id !== 'number') throw new Error('The value provided must be an id.')
try {
const response = await fetch(`${endpoint}collections/${id}`)
if (!response.ok) throw new Error(`HTTP error: ${response.status}`)
return await response.json()
} catch (error) {
console.error('Error fetching collection metadata:', error)
}
},
async getItemsInCollectionById(endpoint, id) {
try {
const collection = await this.getCollectionMetadataById(endpoint, id)
const response = await fetch(collection.items.url)
if (!response.ok) throw new Error(`HTTP error: ${response.status}`)
return await response.json()
} catch (error) {
console.error('Error fetching items in collection by ID:', error)
}
},
async getExhibits(endpoint) {
try {
const response = await fetch(`${endpoint}exhibits`)
if (!response.ok) throw new Error(`HTTP error: ${response.status}`)
return await response.json()
} catch (error) {
console.error('Error fetching exhibits:', error)
}
},
async getExhibitMetadataById(endpoint, id) {
if (typeof id !== 'number') throw new Error('The value provided must be an id.')
try {
const response = await fetch(`${endpoint}exhibits/${id}`)
if (!response.ok) throw new Error(`HTTP error: ${response.status}`)
return await response.json()
} catch (error) {
console.error('Error fetching exhibit metadata:', error)
}
},
async getPagesInExhibit(endpoint, id) {
try {
const exhibit = await this.getExhibitMetadataById(endpoint, id)
const response = await fetch(exhibit.pages.url)
if (!response.ok) throw new Error(`HTTP error: ${response.status}`)
return await response.json()
} catch (error) {
console.error('Error fetching pages in exhibit:', error)
}
}
}
export default API