Skip to content

Commit 9d9b732

Browse files
committed
Show ID in log outputs
1 parent f45021a commit 9d9b732

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/upload/lesson.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import defaultsDeep from "lodash/defaultsDeep";
1616
export const websockets: WebSocket[] = [];
1717

1818
/**
19-
* Handles a lesson manifest.
19+
* Handles a lesson manifest and returns its actual ID.
2020
* @param state {State} - is the application's state.
2121
* @param id {string} - is the friendly name of the lesson.
2222
* @param name {string} - is the display name of the lesson.
@@ -33,7 +33,7 @@ export async function handleLesson(
3333
templateDir: string | null,
3434
lessonClass: number,
3535
dir: string,
36-
): Promise<void> {
36+
): Promise<string> {
3737
// We need to first figure out what the ID of this lesson is.
3838
// If it doesn't exist, we'll just set it to null.
3939
const actualID: string | null = await axios
@@ -225,7 +225,10 @@ export async function handleLesson(
225225
if (!token) throw new Error("Could not get a token!");
226226

227227
// Next, let's open a websocket channel.
228-
return uploadFiles(token, files);
228+
await uploadFiles(token, files);
229+
230+
// And finally, return the lesson ID.
231+
return lessonID;
229232
}
230233

231234
function uploadFiles(

src/upload/manifest.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ export async function readManifest(
6868
if (typeof lessons !== "object" || Array.isArray(lessons))
6969
throw new Error("lessons must be an object!");
7070

71-
await handleUnit(state, id, name, lessons);
71+
const unitID = await handleUnit(state, id, name, lessons);
72+
console.log(`Uploaded Unit "${manifest}" (ID: "${unitID}").`);
73+
7274
break;
7375
}
7476
case "lesson": {
@@ -110,7 +112,7 @@ export async function readManifest(
110112
"]!",
111113
);
112114

113-
await handleLesson(
115+
const lessonID = await handleLesson(
114116
state,
115117
id,
116118
name,
@@ -119,6 +121,8 @@ export async function readManifest(
119121
classMap[lessonClass] || 0,
120122
Path.dirname(manifest),
121123
);
124+
console.log(`Uploaded Lesson "${manifest}" (ID: "${lessonID}").`);
125+
122126
break;
123127
}
124128
default: {
@@ -128,8 +132,6 @@ export async function readManifest(
128132
}
129133
}
130134

131-
console.log(`Uploaded ${manifest}.`);
132-
133135
// Handle delays.
134136
await delay(state);
135137
} catch (e) {

src/upload/unit.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import axios, { AxiosError } from "axios";
22
import { delay, State } from "./index";
33

44
/**
5-
* Handles a unit manifest.
5+
* Handles a unit manifest and returns its actual ID.
66
* @param state {State} - is the application's state.
77
* @param id {string} - is the friendly name of the unit.
88
* @param name {string} - is the display name of the unit.
@@ -16,7 +16,7 @@ export async function handleUnit(
1616
string,
1717
{ next: string[]; previous: string[]; requireAll?: boolean }
1818
>,
19-
): Promise<void> {
19+
): Promise<string> {
2020
// First, we need to figure out what the actual ID of our unit is.
2121
// If there isn't one, we'll just set it to null.
2222
const actualID: string | null = await axios
@@ -71,7 +71,7 @@ export async function handleUnit(
7171
}
7272

7373
// Create or update the unit.
74-
await axios.put(
74+
const unitID = await axios.put(
7575
"https://cratecode.com/internal/api/unit",
7676
{
7777
id: actualID,
@@ -84,8 +84,11 @@ export async function handleUnit(
8484
authorization: state.key,
8585
},
8686
},
87-
);
87+
).then((res) => res.data.id as string);
8888
await delay(state);
89+
90+
// And finally, return the unit ID.
91+
return unitID;
8992
}
9093

9194
/**

0 commit comments

Comments
 (0)