-
Notifications
You must be signed in to change notification settings - Fork 3
/
api.py
55 lines (47 loc) · 1.33 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from fastapi import FastAPI, File, UploadFile, Form
from fastapi.middleware.cors import CORSMiddleware
import uuid
import os
from task import main
from Services.YamlParserService import parse
from index_web import index_web
import globals
app = FastAPI()
origins = [
globals.CORS_ORIGIN
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.post("/index/file/")
def index_file(file: UploadFile = File(...), yaml: UploadFile = File(...)):
yaml_file = yaml.filename
with open(yaml_file, 'wb') as f:
f.write(yaml.file.read())
group_array = parse(yaml_file)
print(group_array)
new_directory = "Downloads/" + str(uuid.uuid4()) + "/"
os.mkdir(new_directory)
file_name = file.filename
saved_file = new_directory + str(file_name)
with open(saved_file, 'wb') as f:
f.write(file.file.read())
saved_file_info = {
"file": saved_file,
"directory": new_directory
}
main.delay(saved_file_info, group_array, api_mode=True)
return True
@app.post("/index/websites/")
def website(urls: str = Form(...)):
urls = [x.strip() for x in urls.split(',')]
print(type(urls))
print(len(urls))
for url in urls:
print(url)
index_web.delay(str(url))
return True