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);
|
||||
body.innerHTML = null;
|
||||
}
|
||||
// cleat attachment
|
||||
const input = document.getElementById('attachment');
|
||||
input.value = "";
|
||||
// clear attachment
|
||||
const attachments = document.getElementById('attachments');
|
||||
attachments.innerHTML = null;
|
||||
const attachment = document.getElementById('attachment');
|
||||
attachment.value = "";
|
||||
}
|
||||
|
||||
function select_part()
|
||||
|
|
|
@ -460,11 +460,11 @@ get '/import/lcsc/:lcsc' do
|
|||
end
|
||||
|
||||
get '/attach?' do
|
||||
halt 401, "part name or id required" unless params['id'] or params['name']
|
||||
halt 401, "attachement URL required" unless params['url']
|
||||
halt 400, "part name or id required" unless params['id'] or params['name']
|
||||
halt 400, "attachement URL required" unless params['url']
|
||||
statement = @db.prepare("SELECT id, name FROM part WHERE id = ? OR name = ?")
|
||||
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]
|
||||
dir = PUBLIC + "/" + ATTACHMENTS + "/" + part["name"].gsub("/", "_")
|
||||
path = "#{dir}/#{file}"
|
||||
|
@ -476,6 +476,8 @@ get '/attach?' do
|
|||
File.open(path, "wb") do |f|
|
||||
f.write res.body
|
||||
end
|
||||
else
|
||||
halt 404, "download failed"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue