If the following is a list of links to your video site, if people want to crawl your data is very easy, see the rules will know that the database is a sequential increase
Http://www.xxxx.com/video/1
Http://www.xxxx.com/video/2
Http://www.xxxx.com/video/3
So to solve this problem, we can use the short address, do not expose the real link, using symmetric encryption is a good solution.
Hashids is a good choice, it provides the implementation of Js/php/java/python and other programming languages, I use it here.
Below is the Java Short Address service I built based on the blade framework.
CREATE TABLE ' T_url ' (
' id ' int () NOT NULL auto_increment,
' url ' text not null,
PRIMARY KEY (' id ')
) ENG Ine=innodb auto_increment=15 DEFAULT Charset=utf8;
Routing
@Path public class Indexroute {//Salt value private static final hashids Hashids = new Hashids ("Blade-shorturl");
Private Urlmodel Urlmodel = new Urlmodel (); @Route ("/:key") public void Get (Request req, Response Response) {String key = Req.pathparam (": Key"). ReplaceAll ("[^a
-ZA-Z0-9] "," "");
long[] numbers = Hashids.decode (key);
if (null = = Numbers | | Numbers.length < 1) {Response.text ("not Found");
Return
int id = (int) numbers[0];
String result = Get (ID). GETURL ();
if (result = = null) {Response.text ("not Found");
Return
} Response.Redirect (Result);
@Route (value = "/", method = httpmethod.get) Public String index () {return ' index '; @Route (value = "/", method = httpmethod.post) public String Save (Request request, Response Response) {Strin
G resjsp = "index";
String Longurl = request.query ("url");
if (!isurl (Longurl)) {Request.attribute ("error", "Invalid URL"); return resjsp;
Integer id = this.save (longurl);
if (id = = 0) {request.attribute ("error", "Save Failed");
return resjsp;
String hash = Hashids.encode (ID);
Request.attribute ("Url_hash", hash);
SYSTEM.OUT.PRINTLN ("id =" + id + ", url_hash=" + hash);
return resjsp;
Private Integer Save (String URL) {return Urlmodel.insert (). param ("url", url). Executeandcommit ();
Private Urlmodel get (int id) {return urlmodel.fetchbypk (ID); Private final String REGEX = "\\b" (https?| Ftp|file)://[-a-za-z0-9+&@#/%?=~_|!:,.;]
*[-a-za-z0-9+&@#/%=~_|] ";
Private Boolean isurl (String URL) {if (Stringkit.isnotblank (URL)) {Pattern pattern = pattern.compile (REGEX);
Matcher Matcher = pattern.matcher (URL);
if (Matcher.find ()) {return true;
return false; }
}
Implementation effect:
Code Location: Https://github.com/bladejava/blade-shorturl
The above is the entire content of this article, I hope to help you learn.