[webui,api] move the rdiff function from webui

to api to avoid duplicatin a rather huge function