Skip to content

Commit 8755708

Browse files
committed
Simplify manifest entity saving
1 parent 9fcad4a commit 8755708

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ const getManifest = async (siteId: string, branchOrRef: string) => {
4747
if (latestManifest) {
4848
return latestManifest;
4949
}
50-
return result;
5150
};
5251

5352
const parseHostname = (hostname: string) => {

src/upload.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ function createScheduleItem(
148148
} as ScheduleItem;
149149
}
150150

151+
async function saveManifestEntity(key: entity.Key, data: any) {
152+
const ent = {
153+
key: key,
154+
excludeFromIndexes: ['schedule'],
155+
data: data,
156+
};
157+
await datastore.save(ent);
158+
}
159+
151160
async function finalize(manifest: Manifest, ttl?: Date) {
152161
const manifestPaths = manifest.toJSON();
153162
const now = new Date();
@@ -160,17 +169,12 @@ async function finalize(manifest: Manifest, ttl?: Date) {
160169
const scheduleItem = createScheduleItem(manifest, manifestPaths, now);
161170
const schedule: Record<string, ScheduleItem> = {};
162171
schedule[now.toString()] = scheduleItem;
163-
const ent = {
164-
key: key,
165-
excludeFromIndexes: ['schedule'],
166-
data: {
167-
site: manifest.site,
168-
ref: manifest.ref,
169-
branch: manifest.branch,
170-
schedule: schedule,
171-
},
172-
};
173-
await datastore.save(ent);
172+
await saveManifestEntity(key, {
173+
site: manifest.site,
174+
ref: manifest.ref,
175+
branch: manifest.branch,
176+
schedule: schedule,
177+
});
174178

175179
// Create branch mapping.
176180
if (manifest.branch) {
@@ -204,12 +208,7 @@ async function finalize(manifest: Manifest, ttl?: Date) {
204208
existingData.schedule
205209
)}`
206210
);
207-
const branchEnt = {
208-
key: branchKey,
209-
excludeFromIndexes: ['schedule'],
210-
data: existingData,
211-
};
212-
await datastore.save(branchEnt);
211+
await saveManifestEntity(branchKey, existingData);
213212
}
214213

215214
console.log(

0 commit comments

Comments
 (0)