Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export default class EmbedCodeFile extends Plugin {

if (srcPath.startsWith("https://") || srcPath.startsWith("http://")) {
try {
let httpResp = await requestUrl({url: srcPath, method: "GET"})
let requestParams = {url: srcPath, method: "GET"}
if (this.settings.authToken) {
requestParams["headers"] = {"Authorization": `token ${this.settings.authToken}`}
}
let httpResp = await requestUrl(requestParams)
fullSrc = httpResp.text
} catch(e) {
const errMsg = `\`ERROR: could't fetch '${srcPath}'\``
Expand Down
15 changes: 13 additions & 2 deletions settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ export interface EmbedCodeFileSettings {
includedLanguages: string;
titleBackgroundColor: string;
titleFontColor: string;
authToken: string;
}

export const DEFAULT_SETTINGS: EmbedCodeFileSettings = {
includedLanguages: 'c,cs,cpp,java,python,go,ruby,javascript,js,typescript,ts,shell,sh,bash',
titleBackgroundColor: "#00000020",
titleFontColor: ""
titleFontColor: "",
authToken: ""
}

export class EmbedCodeFileSettingTab extends PluginSettingTab {
Expand Down Expand Up @@ -48,7 +50,7 @@ export class EmbedCodeFileSettingTab extends PluginSettingTab {
this.plugin.settings.titleFontColor = value;
await this.plugin.saveSettings();
}));

new Setting(containerEl)
.setName('Background color of title')
.addText(text => text
Expand All @@ -58,5 +60,14 @@ export class EmbedCodeFileSettingTab extends PluginSettingTab {
this.plugin.settings.titleBackgroundColor = value;
await this.plugin.saveSettings();
}));
new Setting(containerEl)
.setName('API auth token to fetch code from private repos')
.addText(text => text
.setPlaceholder('Enter a token')
.setValue(this.plugin.settings.authToken)
.onChange(async (value) => {
this.plugin.settings.authToken = value;
await this.plugin.saveSettings();
}));
}
}