Compare commits
2 Commits
64cd25675b
...
6d2b15329f
Author | SHA1 | Date |
---|---|---|
King Kévin | 6d2b15329f | |
King Kévin | 3ffaf22368 |
|
@ -89,9 +89,11 @@ function clear()
|
||||||
const body = document.getElementById(table);
|
const body = document.getElementById(table);
|
||||||
body.innerHTML = null;
|
body.innerHTML = null;
|
||||||
}
|
}
|
||||||
// cleat attachment
|
// clear attachment
|
||||||
const input = document.getElementById('attachment');
|
const attachments = document.getElementById('attachments');
|
||||||
input.value = "";
|
attachments.innerHTML = null;
|
||||||
|
const attachment = document.getElementById('attachment');
|
||||||
|
attachment.value = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
function select_part()
|
function select_part()
|
||||||
|
|
|
@ -460,11 +460,11 @@ get '/import/lcsc/:lcsc' do
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/attach?' do
|
get '/attach?' do
|
||||||
halt 401, "part name or id required" unless params['id'] or params['name']
|
halt 400, "part name or id required" unless params['id'] or params['name']
|
||||||
halt 401, "attachement URL required" unless params['url']
|
halt 400, "attachement URL required" unless params['url']
|
||||||
statement = @db.prepare("SELECT id, name FROM part WHERE id = ? OR name = ?")
|
statement = @db.prepare("SELECT id, name FROM part WHERE id = ? OR name = ?")
|
||||||
part = statement.execute(params['id'], params['name']).to_a[0]
|
part = statement.execute(params['id'], params['name']).to_a[0]
|
||||||
halt 401, "unknown part" unless part
|
halt 400, "unknown part" unless part
|
||||||
file = CGI.unescape(params['url']).split("/")[-1]
|
file = CGI.unescape(params['url']).split("/")[-1]
|
||||||
dir = PUBLIC + "/" + ATTACHMENTS + "/" + part["name"].gsub("/", "_")
|
dir = PUBLIC + "/" + ATTACHMENTS + "/" + part["name"].gsub("/", "_")
|
||||||
path = "#{dir}/#{file}"
|
path = "#{dir}/#{file}"
|
||||||
|
@ -476,6 +476,8 @@ get '/attach?' do
|
||||||
File.open(path, "wb") do |f|
|
File.open(path, "wb") do |f|
|
||||||
f.write res.body
|
f.write res.body
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
halt 404, "download failed"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue