based on patchset from https://github.com/haiwen/seafile-server/pull/119 and adapted to recent seafile-server version