changes to imports & import Embeddings

This commit is contained in:
2024-07-12 22:00:29 +02:00
parent b4644ea295
commit bf4bd69337
20 changed files with 751 additions and 140 deletions

View File

@@ -1,12 +1,9 @@
import { Module } from '@nestjs/common';
import { PassportModule } from '@nestjs/passport';
import path from 'path';
import { fileURLToPath } from 'url';
import { JwtStrategy } from '../jwt.strategy.js';
import { AuthController } from './auth.controller.js';
import { AuthService } from './auth.service.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@Module({
imports: [PassportModule],
providers: [AuthService, JwtStrategy],

View File

@@ -1,11 +1,9 @@
import { Injectable } from '@nestjs/common';
// import got from 'got';
import ky from 'ky';
import urlcat from 'urlcat';
@Injectable()
export class AuthService {
public async getAccessToken() {
const form = new FormData();
form.append('grant_type', 'password');
@@ -19,13 +17,15 @@ export class AuthService {
params.append('password', process.env.password);
const URL = `${process.env.host}${process.env.tokenURL}`;
const response = await ky.post(URL, {
body: params.toString(),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization':'Basic YWRtaW4tY2xpOnE0RmJnazFkd0NaelFQZmt5VzhhM3NnckV5UHZlRUY3'
},
}).json();
const response = await ky
.post(URL, {
body: params.toString(),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: 'Basic YWRtaW4tY2xpOnE0RmJnazFkd0NaelFQZmt5VzhhM3NnckV5UHZlRUY3',
},
})
.json();
return (<any>response).access_token;
} catch (error) {
if (error.name === 'HTTPError') {
@@ -37,71 +37,83 @@ export class AuthService {
}
}
public async getUsers(){
public async getUsers() {
const token = await this.getAccessToken();
const URL = `${process.env.host}${process.env.usersURL}`;
const response = await ky.get(URL, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization':`Bearer ${token}`
},
}).json();
return response
const response = await ky
.get(URL, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `Bearer ${token}`,
},
})
.json();
return response;
}
public async getUser(userid:string){
public async getUser(userid: string) {
const token = await this.getAccessToken();
const URL = urlcat(process.env.host,process.env.userURL,{userid})
const response = await ky.get(URL, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization':`Bearer ${token}`
},
}).json();
return response
const URL = urlcat(process.env.host, process.env.userURL, { userid });
const response = await ky
.get(URL, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `Bearer ${token}`,
},
})
.json();
return response;
}
public async getGroups(){
public async getGroups() {
const token = await this.getAccessToken();
const URL = `${process.env.host}${process.env.groupsURL}`;
const response = await ky.get(URL, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization':`Bearer ${token}`
},
}).json();
return response
const response = await ky
.get(URL, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `Bearer ${token}`,
},
})
.json();
return response;
}
public async getGroupsForUser(userid:string){
public async getGroupsForUser(userid: string) {
const token = await this.getAccessToken();
const URL = urlcat(process.env.host,process.env.userGroupsURL,{userid})
const response = await ky.get(URL, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization':`Bearer ${token}`
},
}).json();
return response
const URL = urlcat(process.env.host, process.env.userGroupsURL, { userid });
const response = await ky
.get(URL, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `Bearer ${token}`,
},
})
.json();
return response;
}
public async getLastLogin(userid:string){
public async getLastLogin(userid: string) {
const token = await this.getAccessToken();
const URL = urlcat(process.env.host,process.env.lastLoginURL,{userid})
const response = await ky.get(URL, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization':`Bearer ${token}`
},
}).json();
return response
const URL = urlcat(process.env.host, process.env.lastLoginURL, { userid });
const response = await ky
.get(URL, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `Bearer ${token}`,
},
})
.json();
return response;
}
public async addUser2Group(userid:string,groupid:string){
public async addUser2Group(userid: string, groupid: string) {
const token = await this.getAccessToken();
const URL = urlcat(process.env.host,process.env.addUser2GroupURL,{userid,groupid})
const response = await ky.put(URL, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization':`Bearer ${token}`
},
}).json();
return response
const URL = urlcat(process.env.host, process.env.addUser2GroupURL, { userid, groupid });
const response = await ky
.put(URL, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `Bearer ${token}`,
},
})
.json();
return response;
}
}