mirror of
https://github.com/lmstudio-ai/lms.git
synced 2025-07-30 13:32:37 +08:00
Add auth (#120)
This commit is contained in:
14
src/ensureAuthenticated.ts
Normal file
14
src/ensureAuthenticated.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { type SimpleLogger } from "@lmstudio/lms-common";
|
||||
import { type LMStudioClient } from "@lmstudio/sdk";
|
||||
import chalk from "chalk";
|
||||
|
||||
export async function ensureAuthenticated(client: LMStudioClient, logger: SimpleLogger) {
|
||||
await client.repository.ensureAuthenticated({
|
||||
onAuthenticationUrl: url => {
|
||||
logger.info("Authentication required. Please visit the following URL to authenticate:");
|
||||
logger.info();
|
||||
logger.info(chalk.greenBright(` ${url}`));
|
||||
logger.info();
|
||||
},
|
||||
});
|
||||
}
|
@ -4,6 +4,7 @@ import { command, positional, string, type Type } from "cmd-ts";
|
||||
import { resolve } from "path";
|
||||
import { createClient, createClientArgs } from "../createClient.js";
|
||||
import { createDownloadPbUpdater } from "../downloadPbUpdater.js";
|
||||
import { ensureAuthenticated } from "../ensureAuthenticated.js";
|
||||
import { exists } from "../exists.js";
|
||||
import { createLogger, logLevelArgs } from "../logLevel.js";
|
||||
import { optionalPositional } from "../optionalPositional.js";
|
||||
@ -51,6 +52,7 @@ export const pull = command({
|
||||
handler: async args => {
|
||||
const logger = createLogger(args);
|
||||
const client = await createClient(logger, args);
|
||||
await ensureAuthenticated(client, logger);
|
||||
const { owner, name } = args.artifactIdentifier;
|
||||
let path = args.path;
|
||||
let autoNamed: boolean;
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { command } from "cmd-ts";
|
||||
import { cwd } from "process";
|
||||
import { createClient, createClientArgs } from "../createClient.js";
|
||||
import { ensureAuthenticated } from "../ensureAuthenticated.js";
|
||||
import { findProjectFolderOrExit } from "../findProjectFolder.js";
|
||||
import { createLogger, logLevelArgs } from "../logLevel.js";
|
||||
|
||||
@ -14,6 +15,7 @@ export const push = command({
|
||||
handler: async args => {
|
||||
const logger = createLogger(args);
|
||||
const client = await createClient(logger, args);
|
||||
await ensureAuthenticated(client, logger);
|
||||
const projectPath = await findProjectFolderOrExit(logger, cwd());
|
||||
await client.repository.pushArtifact({
|
||||
path: projectPath,
|
||||
|
Reference in New Issue
Block a user