forked from React-Group/interstellar_ai
		
	Merge branch 'main' into main
This commit is contained in:
		
						commit
						f94b99d357
					
				
					 4 changed files with 43 additions and 22 deletions
				
			
		|  | @ -1,22 +1,22 @@ | ||||||
| type ChatMessage = { | type ChatMessage = { | ||||||
|     name: string; |     name: string; | ||||||
|     message: any; |     messages: any; | ||||||
|     timestamp: number; |     timestamp: number; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| let chatHistory: ChatMessage[] = []; | let chatHistory: ChatMessage[] = []; | ||||||
| 
 | 
 | ||||||
| function addMessage(name: string, message: any): void { | function addMessageHistory(name: string, message: any): void { | ||||||
|     const newMessage: ChatMessage = { |     const newMessage: ChatMessage = { | ||||||
|         name: name, |         name: name, | ||||||
|         message: message, |         messages: message, | ||||||
|         timestamp: Date.now() |         timestamp: Date.now() | ||||||
|     }; |     }; | ||||||
|     chatHistory.push(newMessage); |     chatHistory.push(newMessage); | ||||||
|     console.log(`Added message from ${name}: ${message}`); |     console.log(`Added message from ${name}: ${message}`); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function removeMessage(timestamp: number): void { | function removeMessageHistory(timestamp: number): void { | ||||||
|     const index = chatHistory.findIndex((msg) => msg.timestamp === timestamp); |     const index = chatHistory.findIndex((msg) => msg.timestamp === timestamp); | ||||||
|     if (index > -1) { |     if (index > -1) { | ||||||
|         chatHistory.splice(index, 1); |         chatHistory.splice(index, 1); | ||||||
|  |  | ||||||
|  | @ -68,7 +68,7 @@ export const changePassword = async (usernameOrEmail: string, password: string, | ||||||
| 
 | 
 | ||||||
| export const getData = async (usernameOrEmail: string, password: string) => { | export const getData = async (usernameOrEmail: string, password: string) => { | ||||||
|   const data = { |   const data = { | ||||||
|     action: "get_data", |     action: "get_settings", | ||||||
|     username: usernameOrEmail.includes('@') ? undefined : usernameOrEmail, |     username: usernameOrEmail.includes('@') ? undefined : usernameOrEmail, | ||||||
|     email: usernameOrEmail.includes('@') ? usernameOrEmail : undefined, |     email: usernameOrEmail.includes('@') ? usernameOrEmail : undefined, | ||||||
|     password, |     password, | ||||||
|  | @ -98,7 +98,7 @@ export const getName = async (usernameOrEmail: string, password: string): Promis | ||||||
| 
 | 
 | ||||||
| export const changeData = async (usernameOrEmail: string, password: string, newData: any) => { | export const changeData = async (usernameOrEmail: string, password: string, newData: any) => { | ||||||
|   const data = { |   const data = { | ||||||
|     action: "change_data", |     action: "change_settings", | ||||||
|     username: usernameOrEmail.includes('@') ? undefined : usernameOrEmail, |     username: usernameOrEmail.includes('@') ? undefined : usernameOrEmail, | ||||||
|     email: usernameOrEmail.includes('@') ? usernameOrEmail : undefined, |     email: usernameOrEmail.includes('@') ? usernameOrEmail : undefined, | ||||||
|     password, |     password, | ||||||
|  |  | ||||||
							
								
								
									
										12
									
								
								py/api.py
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								py/api.py
									
										
									
									
									
								
							|  | @ -103,10 +103,14 @@ class API: | ||||||
|                 return jsonify({'status': 200, 'response': self.db.add_user(sent_data)}) |                 return jsonify({'status': 200, 'response': self.db.add_user(sent_data)}) | ||||||
|             elif action == "change_password": |             elif action == "change_password": | ||||||
|                 return jsonify({'status': 200, 'response': self.db.update_password(sent_data)}) |                 return jsonify({'status': 200, 'response': self.db.update_password(sent_data)}) | ||||||
|             elif action == "get_data": |             elif action == "get_settings": | ||||||
|                 return jsonify({'status': 200, 'response': self.db.get_data(sent_data)}) |                 return jsonify({'status': 200, 'response': self.db.get_settings(sent_data)}) | ||||||
|             elif action == "change_data": |             elif action == "change_settings": | ||||||
|                 return jsonify({'status': 200, 'response': self.db.change_data(sent_data)}) |                 return jsonify({'status': 200, 'response': self.db.change_settings(sent_data)}) | ||||||
|  |             elif action == "get_history": | ||||||
|  |                 return jsonify({'status': 200, 'response': self.db.get_history(sent_data)}) | ||||||
|  |             elif action == "change_history": | ||||||
|  |                 return jsonify({'status': 200, 'response': self.db.change_history(sent_data)}) | ||||||
|             elif action == "check_credentials": |             elif action == "check_credentials": | ||||||
|                 return jsonify({'status': 200, 'response': self.db.check_credentials(sent_data)}) |                 return jsonify({'status': 200, 'response': self.db.check_credentials(sent_data)}) | ||||||
|             elif action == "delete_account": |             elif action == "delete_account": | ||||||
|  |  | ||||||
							
								
								
									
										41
									
								
								py/db.py
									
										
									
									
									
								
							
							
						
						
									
										41
									
								
								py/db.py
									
										
									
									
									
								
							|  | @ -27,7 +27,7 @@ class DB: | ||||||
|         password = data.get('password') |         password = data.get('password') | ||||||
|         email = data.get('email') |         email = data.get('email') | ||||||
|         hashed_password = self.hash_password(password) |         hashed_password = self.hash_password(password) | ||||||
|         user_data = {"hashed_password": hashed_password, "email": email, "data": None} |         user_data = {"hashed_password": hashed_password, "email": email, "settings": None, "history": None} | ||||||
|         if username not in self.database: |         if username not in self.database: | ||||||
|             self.database[username] = user_data |             self.database[username] = user_data | ||||||
|             self.save_database() |             self.save_database() | ||||||
|  | @ -43,15 +43,6 @@ class DB: | ||||||
|         self.save_database() |         self.save_database() | ||||||
|         return True |         return True | ||||||
| 
 | 
 | ||||||
|     def change_data(self, data): |  | ||||||
|         username = self.ensure_username(data) |  | ||||||
|         if not self.check_credentials(data): |  | ||||||
|             return False |  | ||||||
| 
 |  | ||||||
|         self.database[username]['data'] = data.get('data') |  | ||||||
|         self.save_database() |  | ||||||
|         return True |  | ||||||
| 
 |  | ||||||
|     def update_password(self, data): |     def update_password(self, data): | ||||||
|         username = self.ensure_username(data) |         username = self.ensure_username(data) | ||||||
|         new_password = data.get('new_password') |         new_password = data.get('new_password') | ||||||
|  | @ -74,12 +65,38 @@ class DB: | ||||||
|         print(stored_hashed_password == entered_hashed_password) |         print(stored_hashed_password == entered_hashed_password) | ||||||
|         return stored_hashed_password == entered_hashed_password |         return stored_hashed_password == entered_hashed_password | ||||||
| 
 | 
 | ||||||
|     def get_data(self, data): |     def change_settings(self, data): | ||||||
|  |         username = self.ensure_username(data) | ||||||
|  |         if not self.check_credentials(data): | ||||||
|  |             return False | ||||||
|  | 
 | ||||||
|  |         self.database[username]['settings'] = data.get('data') | ||||||
|  |         self.save_database() | ||||||
|  |         return True | ||||||
|  | 
 | ||||||
|  |     def get_settings(self, data): | ||||||
|         username = self.ensure_username(data) |         username = self.ensure_username(data) | ||||||
|         if not self.check_credentials(data): |         if not self.check_credentials(data): | ||||||
|             return None |             return None | ||||||
| 
 | 
 | ||||||
|         send_back = self.database[username].get('data') |         send_back = self.database[username].get('settings') | ||||||
|  |         return send_back | ||||||
|  | 
 | ||||||
|  |     def change_history(self, data): | ||||||
|  |         username = self.ensure_username(data) | ||||||
|  |         if not self.check_credentials(data): | ||||||
|  |             return False | ||||||
|  | 
 | ||||||
|  |         self.database[username]['history'] = data.get('data') | ||||||
|  |         self.save_database() | ||||||
|  |         return True | ||||||
|  | 
 | ||||||
|  |     def get_history(self, data): | ||||||
|  |         username = self.ensure_username(data) | ||||||
|  |         if not self.check_credentials(data): | ||||||
|  |             return None | ||||||
|  | 
 | ||||||
|  |         send_back = self.database[username].get('history') | ||||||
|         return send_back |         return send_back | ||||||
| 
 | 
 | ||||||
|     def get_email(self, data): |     def get_email(self, data): | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue